diff --git a/builder/profitbricks/step_create_server.go b/builder/profitbricks/step_create_server.go index f9e7ff140..ef606e380 100644 --- a/builder/profitbricks/step_create_server.go +++ b/builder/profitbricks/step_create_server.go @@ -72,7 +72,11 @@ func (s *stepCreateServer) Run(state multistep.StateBag) multistep.StepAction { if datacenter.StatusCode > 299 { if datacenter.StatusCode > 299 { var restError RestError - json.Unmarshal([]byte(datacenter.Response), &restError) + err := json.Unmarshal([]byte(datacenter.Response), &restError) + if err != nil { + ui.Error(fmt.Sprintf("Error decoding json response: %s", err.Error())) + return multistep.ActionHalt + } if len(restError.Messages) > 0 { ui.Error(restError.Messages[0].Message) } else { @@ -147,9 +151,11 @@ func (s *stepCreateServer) Cleanup(state multistep.StateBag) { if dcId, ok := state.GetOk("datacenter_id"); ok { resp := profitbricks.DeleteDatacenter(dcId.(string)) - s.checkForErrors(resp) - err := s.waitTillProvisioned(resp.Headers.Get("Location"), *c) - if err != nil { + if err := s.checkForErrors(resp); err != nil { + ui.Error(fmt.Sprintf( + "Error deleting Virtual Data Center. Please destroy it manually: %s", err)) + } + if err := s.waitTillProvisioned(resp.Headers.Get("Location"), *c); err != nil { ui.Error(fmt.Sprintf( "Error deleting Virtual Data Center. Please destroy it manually: %s", err)) } diff --git a/builder/profitbricks/step_take_snapshot.go b/builder/profitbricks/step_take_snapshot.go index 35820f3e1..1c172daef 100644 --- a/builder/profitbricks/step_take_snapshot.go +++ b/builder/profitbricks/step_take_snapshot.go @@ -28,7 +28,10 @@ func (s *stepTakeSnapshot) Run(state multistep.StateBag) multistep.StepAction { if snapshot.StatusCode > 299 { var restError RestError - json.Unmarshal([]byte(snapshot.Response), &restError) + if err := json.Unmarshal([]byte(snapshot.Response), &restError); err != nil { + ui.Error(err.Error()) + return multistep.ActionHalt + } if len(restError.Messages) > 0 { ui.Error(restError.Messages[0].Message) } else { diff --git a/post-processor/amazon-import/post-processor.go b/post-processor/amazon-import/post-processor.go index 77ea77cb9..236436e13 100644 --- a/post-processor/amazon-import/post-processor.go +++ b/post-processor/amazon-import/post-processor.go @@ -239,7 +239,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac return nil, false, fmt.Errorf("Error waiting for AMI (%s): %s", *resp.ImageId, err) } - ec2conn.DeregisterImage(&ec2.DeregisterImageInput{ + _, err = ec2conn.DeregisterImage(&ec2.DeregisterImageInput{ ImageId: &createdami, }) diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index 642d99bd8..0577c58f3 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -355,7 +355,9 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri go repeat(stderr) log.Printf("Executing Ansible: %s", strings.Join(cmd.Args, " ")) - cmd.Start() + if err := cmd.Start(); err != nil { + return err + } wg.Wait() err = cmd.Wait() if err != nil { diff --git a/provisioner/ansible/scp.go b/provisioner/ansible/scp.go index b36b22590..6378bdc14 100644 --- a/provisioner/ansible/scp.go +++ b/provisioner/ansible/scp.go @@ -104,8 +104,7 @@ func (state *scpDownloadState) FileProtocol(path string, info os.FileInfo, in *b size := info.Size() perms := fmt.Sprintf("C%04o", info.Mode().Perm()) fmt.Fprintln(out, perms, size, info.Name()) - err := scpResponse(in) - if err != nil { + if err := scpResponse(in); err != nil { return err } @@ -194,8 +193,7 @@ func (state *scpUploadState) FileProtocol(in *bufio.Reader, out io.Writer) error return err } - err = scpResponse(in) - if err != nil { + if err := scpResponse(in); err != nil { return err } @@ -260,7 +258,9 @@ type scpDownloadState struct { func (state *scpDownloadState) Protocol(in *bufio.Reader, out io.Writer) error { r := bufio.NewReader(in) // read the byte sent by the other side to start the transfer - scpResponse(r) + if err := scpResponse(r); err != nil { + return err + } return filepath.Walk(state.srcRoot, func(path string, info os.FileInfo, err error) error { if err != nil {