Don't print "context canceled" if user terminated
Without breaking API compatibility, this patch allows us to know whether a returned `cli/StatusError` was caused by a context cancellation or not, which we can use to provide a nicer UX and not print the Go "context canceled" error message if this is the cause. Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
14
cli/error.go
14
cli/error.go
@ -6,6 +6,7 @@ import (
|
||||
|
||||
// StatusError reports an unsuccessful exit by a command.
|
||||
type StatusError struct {
|
||||
Cause error
|
||||
Status string
|
||||
StatusCode int
|
||||
}
|
||||
@ -14,8 +15,15 @@ type StatusError struct {
|
||||
// it is returned as-is, otherwise it generates a generic error-message
|
||||
// based on the StatusCode.
|
||||
func (e StatusError) Error() string {
|
||||
if e.Status == "" {
|
||||
return "exit status " + strconv.Itoa(e.StatusCode)
|
||||
if e.Status != "" {
|
||||
return e.Status
|
||||
}
|
||||
return e.Status
|
||||
if e.Cause != nil {
|
||||
return e.Cause.Error()
|
||||
}
|
||||
return "exit status " + strconv.Itoa(e.StatusCode)
|
||||
}
|
||||
|
||||
func (e StatusError) Unwrap() error {
|
||||
return e.Cause
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user