From 7a1680df97e028c4a75622effe08f6610d0ee5b4 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 5 Nov 2020 02:27:07 -0800 Subject: [PATCH] modify a ton of error messages to make them specifically placable. (#10191) * modify a ton of error messages to make them specifically placable. * remove specific loglines but keep the specialized error messages Co-authored-by: Adrien Delorme --- builder/vsphere/clone/step_clone.go | 2 +- builder/vsphere/driver/datastore.go | 8 ++++---- builder/vsphere/driver/vm.go | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/builder/vsphere/clone/step_clone.go b/builder/vsphere/clone/step_clone.go index 17da84ad1..e0a504b54 100644 --- a/builder/vsphere/clone/step_clone.go +++ b/builder/vsphere/clone/step_clone.go @@ -85,7 +85,7 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist ui.Say("Cloning VM...") template, err := d.FindVM(s.Config.Template) if err != nil { - state.Put("error", err) + state.Put("error", fmt.Errorf("Error finding vm to clone: %s", err)) return multistep.ActionHalt } diff --git a/builder/vsphere/driver/datastore.go b/builder/vsphere/driver/datastore.go index adc13447f..ae371b79f 100644 --- a/builder/vsphere/driver/datastore.go +++ b/builder/vsphere/driver/datastore.go @@ -42,12 +42,12 @@ func (d *VCenterDriver) FindDatastore(name string, host string) (Datastore, erro if name == "" { h, err := d.FindHost(host) if err != nil { - return nil, err + return nil, fmt.Errorf("Error finding host for to get datastore: %s", err) } i, err := h.Info("datastore") if err != nil { - return nil, err + return nil, fmt.Errorf("Error getting datastore info from host: %s", err) } if len(i.Datastore) > 1 { @@ -57,14 +57,14 @@ func (d *VCenterDriver) FindDatastore(name string, host string) (Datastore, erro ds := d.NewDatastore(&i.Datastore[0]) inf, err := ds.Info("name") if err != nil { - return nil, err + return nil, fmt.Errorf("Error getting datastore name: %s", err) } name = inf.Name } ds, err := d.finder.Datastore(d.ctx, name) if err != nil { - return nil, err + return nil, fmt.Errorf("Error finding datastore with name %s: %s", name, err) } return &DatastoreDriver{ diff --git a/builder/vsphere/driver/vm.go b/builder/vsphere/driver/vm.go index f0bbf6f6d..8481f3716 100644 --- a/builder/vsphere/driver/vm.go +++ b/builder/vsphere/driver/vm.go @@ -297,21 +297,21 @@ func (vm *VirtualMachineDriver) FloppyDevices() (object.VirtualDeviceList, error func (vm *VirtualMachineDriver) Clone(ctx context.Context, config *CloneConfig) (VirtualMachine, error) { folder, err := vm.driver.FindFolder(config.Folder) if err != nil { - return nil, err + return nil, fmt.Errorf("Error finding filder: %s", err) } var relocateSpec types.VirtualMachineRelocateSpec pool, err := vm.driver.FindResourcePool(config.Cluster, config.Host, config.ResourcePool) if err != nil { - return nil, err + return nil, fmt.Errorf("Error finding resource pool: %s", err) } poolRef := pool.pool.Reference() relocateSpec.Pool = &poolRef datastore, err := vm.driver.FindDatastore(config.Datastore, config.Host) if err != nil { - return nil, err + return nil, fmt.Errorf("Error finding datastore: %s", err) } datastoreRef := datastore.Reference() relocateSpec.Datastore = &datastoreRef @@ -325,7 +325,7 @@ func (vm *VirtualMachineDriver) Clone(ctx context.Context, config *CloneConfig) tpl, err := vm.Info("snapshot") if err != nil { - return nil, err + return nil, fmt.Errorf("Error getting snapshot info for vm: %s", err) } if tpl.Snapshot == nil { err = errors.New("`linked_clone=true`, but template has no snapshots") @@ -344,21 +344,21 @@ func (vm *VirtualMachineDriver) Clone(ctx context.Context, config *CloneConfig) if config.Network != "" { net, err := vm.driver.FindNetwork(config.Network) if err != nil { - return nil, err + return nil, fmt.Errorf("Error finding network: %s", err) } backing, err := net.network.EthernetCardBackingInfo(ctx) if err != nil { - return nil, err + return nil, fmt.Errorf("Error finding ethernet card backing info: %s", err) } devices, err := vm.vm.Device(ctx) if err != nil { - return nil, err + return nil, fmt.Errorf("Error finding vm devices: %s", err) } adapter, err := findNetworkAdapter(devices) if err != nil { - return nil, err + return nil, fmt.Errorf("Error finding network adapter: %s", err) } current := adapter.GetVirtualEthernetCard() @@ -375,13 +375,13 @@ func (vm *VirtualMachineDriver) Clone(ctx context.Context, config *CloneConfig) vAppConfig, err := vm.updateVAppConfig(ctx, config.VAppProperties) if err != nil { - return nil, err + return nil, fmt.Errorf("Error updating VAppConfig: %s", err) } configSpec.VAppConfig = vAppConfig task, err := vm.vm.Clone(vm.driver.ctx, folder.folder, config.Name, cloneSpec) if err != nil { - return nil, err + return nil, fmt.Errorf("Error calling vm.vm.Clone task: %s", err) } info, err := task.WaitForResult(ctx, nil) @@ -391,7 +391,7 @@ func (vm *VirtualMachineDriver) Clone(ctx context.Context, config *CloneConfig) return nil, err } - return nil, err + return nil, fmt.Errorf("Error waiting for vm Clone to complete: %s", err) } vmRef, ok := info.Result.(types.ManagedObjectReference)