x/crypto/ssh: omit empty fields in error message Although the signal and msg fields are assigned together, their values originate from the remote server and may be empty. Fixes golang/go#14251 Change-Id: I9d9094cc69f3c14bf1648af59951f6b6c7a71e0a Reviewed-on: https://go-review.googlesource.com/22196 Reviewed-by: Han-Wen Nienhuys <hanwen@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/ssh/session.go b/ssh/session.go index fd10cd1..09eb009 100644 --- a/ssh/session.go +++ b/ssh/session.go
@@ -601,5 +601,12 @@ } func (w Waitmsg) String() string { - return fmt.Sprintf("Process exited with: %v. Reason was: %v (%v)", w.status, w.msg, w.signal) + str := fmt.Sprintf("Process exited with status %v", w.status) + if w.signal != "" { + str += fmt.Sprintf(" from signal %v", w.signal) + } + if w.msg != "" { + str += fmt.Sprintf(". Reason was: %v", w.msg) + } + return str }