From cc11ec356649f17fda157e1b5ab8881e3992e90c Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Tue, 28 Mar 2017 20:35:22 -0700 Subject: [PATCH] check for a couple errors --- builder/amazon/chroot/communicator.go | 5 ++++- builder/amazon/common/step_run_source_instance.go | 10 ++++++++-- communicator/ssh/communicator.go | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/builder/amazon/chroot/communicator.go b/builder/amazon/chroot/communicator.go index b77ee03e8..24284efab 100644 --- a/builder/amazon/chroot/communicator.go +++ b/builder/amazon/chroot/communicator.go @@ -69,7 +69,10 @@ func (c *Communicator) Upload(dst string, r io.Reader, fi *os.FileInfo) error { return fmt.Errorf("Error preparing shell script: %s", err) } defer os.Remove(tf.Name()) - io.Copy(tf, r) + + if _, err := io.Copy(tf, r); err != nil { + return err + } cpCmd, err := c.CmdWrapper(fmt.Sprintf("cp %s %s", tf.Name(), dst)) if err != nil { diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index 8ac837875..0f33611a2 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -342,7 +342,10 @@ func (s *StepRunSourceInstance) Cleanup(state multistep.StateBag) { Target: "cancelled", } - WaitForState(&stateChange) + _, err := WaitForState(&stateChange) + if err != nil { + ui.Error(err.Error()) + } } @@ -359,6 +362,9 @@ func (s *StepRunSourceInstance) Cleanup(state multistep.StateBag) { Target: "terminated", } - WaitForState(&stateChange) + _, err := WaitForState(&stateChange) + if err != nil { + ui.Error(err.Error()) + } } } diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 9cef308fb..d9fc0442d 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -250,7 +250,7 @@ func (c *comm) newSession() (session *ssh.Session, err error) { func (c *comm) reconnect() (err error) { if c.conn != nil { - c.conn.Close() + return c.conn.Close() } // Set the conn and client to nil since we'll recreate it