diff --git a/cli/command/network/remove_test.go b/cli/command/network/remove_test.go index 05ec10b1ed56..e3217a187424 100644 --- a/cli/command/network/remove_test.go +++ b/cli/command/network/remove_test.go @@ -90,7 +90,7 @@ func TestNetworkRemoveForce(t *testing.T) { assert.NilError(t, err) } else { assert.Check(t, is.Contains(fakeCli.ErrBuffer().String(), tc.expectedErr)) - assert.ErrorContains(t, err, "Code: 1") + assert.ErrorContains(t, err, "exit status 1") } }) } diff --git a/cli/command/system/info_test.go b/cli/command/system/info_test.go index 616256c4cb9c..038bd493f0f9 100644 --- a/cli/command/system/info_test.go +++ b/cli/command/system/info_test.go @@ -444,7 +444,7 @@ func TestFormatInfo(t *testing.T) { { doc: "syntax", template: "{{}", - expectedError: `Status: template parsing error: template: :1: unexpected "}" in command, Code: 64`, + expectedError: `template parsing error: template: :1: unexpected "}" in command`, }, { doc: "syntax", diff --git a/cli/error.go b/cli/error.go index 62f62433b82b..8fb2ab36717c 100644 --- a/cli/error.go +++ b/cli/error.go @@ -1,7 +1,7 @@ package cli import ( - "fmt" + "strconv" "strings" ) @@ -28,6 +28,12 @@ type StatusError struct { StatusCode int } +// Error formats the error for printing. If a custom Status is provided, +// it is returned as-is, otherwise it generates a generic error-message +// based on the StatusCode. func (e StatusError) Error() string { - return fmt.Sprintf("Status: %s, Code: %d", e.Status, e.StatusCode) + if e.Status == "" { + return "exit status " + strconv.Itoa(e.StatusCode) + } + return e.Status }