Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/command/network/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/system/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions cli/error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cli

import (
"fmt"
"strconv"
"strings"
)

Expand All @@ -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
}