From 92af5847a7de1fddb2f4051cdc3ee7ddfe1ee26d Mon Sep 17 00:00:00 2001 From: Pratyush singhal Date: Tue, 11 Jun 2019 21:01:26 +0530 Subject: [PATCH] refactor: replace *packer.MultiError from type signature of createInstanceMetadata with generic error interface Signed-off-by: Pratyush singhal --- builder/googlecompute/step_create_instance.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index ec056d596..6004c2fab 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -16,7 +16,7 @@ type StepCreateInstance struct { Debug bool } -func (c *Config) createInstanceMetadata(sourceImage *Image, sshPublicKey string) (map[string]string, *packer.MultiError) { +func (c *Config) createInstanceMetadata(sourceImage *Image, sshPublicKey string) (map[string]string, error) { instanceMetadata := make(map[string]string) var err error var errs *packer.MultiError @@ -43,7 +43,7 @@ func (c *Config) createInstanceMetadata(sourceImage *Image, sshPublicKey string) var content []byte content, err = ioutil.ReadFile(c.StartupScriptFile) if err != nil { - errs = packer.MultiErrorAppend(errs, err) + return nil, err } instanceMetadata[StartupWrappedScriptKey] = string(content) } else if wrappedStartupScript, exists := instanceMetadata[StartupScriptKey]; exists { @@ -70,7 +70,10 @@ func (c *Config) createInstanceMetadata(sourceImage *Image, sshPublicKey string) instanceMetadata[StartupScriptStatusKey] = StartupScriptStatusNotDone } - return instanceMetadata, errs + if errs != nil && len(errs.Errors) > 0 { + return instanceMetadata, errs + } + return instanceMetadata, nil } func getImage(c *Config, d Driver) (*Image, error) { @@ -114,9 +117,10 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag) var errCh <-chan error var metadata map[string]string metadata, errs := c.createInstanceMetadata(sourceImage, string(c.Comm.SSHPublicKey)) - if errs != nil && len(errs.Errors) > 0 { + if errs != nil { state.Put("error", errs.Error()) ui.Error(errs.Error()) + return multistep.ActionHalt } errCh, err = d.RunInstance(&InstanceConfig{