print scp error before exiting on error code

See if there is any additional stderr output before exiting, since it
can be helpful in addition to the error status.
This commit is contained in:
James Bardin 2019-02-21 13:42:46 -05:00
parent 0c94e20a83
commit 6cac02df14
1 changed files with 7 additions and 5 deletions

View File

@ -481,6 +481,13 @@ func (c *Communicator) scpSession(scpCommand string, f func(io.Writer, *bufio.Re
// our data and has completed. Or has errored.
log.Println("[DEBUG] Waiting for SSH session to complete.")
err = session.Wait()
// log any stderr before exiting on an error
scpErr := stderr.String()
if len(scpErr) > 0 {
log.Printf("[ERROR] scp stderr: %q", stderr)
}
if err != nil {
if exitErr, ok := err.(*ssh.ExitError); ok {
// Otherwise, we have an ExitErorr, meaning we can just read
@ -499,11 +506,6 @@ func (c *Communicator) scpSession(scpCommand string, f func(io.Writer, *bufio.Re
return err
}
scpErr := stderr.String()
if len(scpErr) > 0 {
log.Printf("[ERROR] scp stderr: %q", stderr)
}
return nil
}