Skip to content

Commit

Permalink
Improve ssh error logging
Browse files Browse the repository at this point in the history
[#145693923]
  • Loading branch information
Henry Stanley committed May 19, 2017
1 parent b52b9b2 commit 577c839
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ssh/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ConnectionCreator(hostName, userName, privateKey string) (SSHConnection, er

parsedPrivateKey, err := ssh.ParsePrivateKey([]byte(privateKey))
if err != nil {
return nil, errors.Wrap(err, "ssh.ParsePrivateKey")
return nil, errors.Wrap(err, "ssh.ConnectionCreator.ParsePrivateKey failed")
}

sshConfig := &ssh.ClientConfig{
Expand All @@ -37,7 +37,7 @@ func ConnectionCreator(hostName, userName, privateKey string) (SSHConnection, er

connection, err := ssh.Dial("tcp", hostName, sshConfig)
if err != nil {
return nil, errors.Wrap(err, "ssh.Dial")
return nil, errors.Wrap(err, "ssh.ConnectionCreator.Dial failed")
}

conn.connection = connection
Expand All @@ -55,13 +55,13 @@ type Connection struct {
func (c Connection) Run(cmd string) ([]byte, []byte, int, error) {
outBuffer := bytes.NewBuffer([]byte{})
errBuffer, exitCode, err := c.Stream(cmd, outBuffer)
return outBuffer.Bytes(), errBuffer, exitCode, errors.Wrap(err, "Stream")
return outBuffer.Bytes(), errBuffer, exitCode, errors.Wrap(err, "ssh.Run.Stream failed")
}

func (c Connection) Stream(cmd string, writer io.Writer) ([]byte, int, error) {
session, err := c.connection.NewSession()
if err != nil {
return nil, 0, errors.Wrap(err, "connection.NewSession")
return nil, 0, errors.Wrap(err, "ssh.Stream.NewSession failed")
}

errBuffer := bytes.NewBuffer([]byte{})
Expand All @@ -75,7 +75,7 @@ func (c Connection) Stream(cmd string, writer io.Writer) ([]byte, int, error) {
if yes {
exitCode = exitErr.ExitStatus()
} else {
return nil, -1, errors.Wrap(err, "session.Run")
return nil, -1, errors.Wrap(err, "ssh.Stream.Run failed")
}

}
Expand All @@ -100,7 +100,7 @@ func (c Connection) StreamStdin(cmd string, reader io.Reader) (stdout, stderr []
if yes {
exitCode = exitErr.ExitStatus()
} else {
return nil, nil, -1, errors.Wrap(err, "expected ssh exiterror")
return nil, nil, -1, errors.Wrap(err, "ssh.StreamStdin.Run failed with non-ExitError failure")
}
}

Expand Down

0 comments on commit 577c839

Please sign in to comment.