Skip to content

Commit cad08ff

Browse files
authored
Merge pull request docker#5231 from thaJeztah/prettier_exit_status
cli: make cli.StatusError slightly prettier
2 parents be6a415 + bca2090 commit cad08ff

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

cli/command/network/remove_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestNetworkRemoveForce(t *testing.T) {
9090
assert.NilError(t, err)
9191
} else {
9292
assert.Check(t, is.Contains(fakeCli.ErrBuffer().String(), tc.expectedErr))
93-
assert.ErrorContains(t, err, "Code: 1")
93+
assert.ErrorContains(t, err, "exit status 1")
9494
}
9595
})
9696
}

cli/command/system/info_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func TestFormatInfo(t *testing.T) {
444444
{
445445
doc: "syntax",
446446
template: "{{}",
447-
expectedError: `Status: template parsing error: template: :1: unexpected "}" in command, Code: 64`,
447+
expectedError: `template parsing error: template: :1: unexpected "}" in command`,
448448
},
449449
{
450450
doc: "syntax",

cli/error.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cli
22

33
import (
4-
"fmt"
4+
"strconv"
55
"strings"
66
)
77

@@ -28,6 +28,12 @@ type StatusError struct {
2828
StatusCode int
2929
}
3030

31+
// Error formats the error for printing. If a custom Status is provided,
32+
// it is returned as-is, otherwise it generates a generic error-message
33+
// based on the StatusCode.
3134
func (e StatusError) Error() string {
32-
return fmt.Sprintf("Status: %s, Code: %d", e.Status, e.StatusCode)
35+
if e.Status == "" {
36+
return "exit status " + strconv.Itoa(e.StatusCode)
37+
}
38+
return e.Status
3339
}

0 commit comments

Comments
 (0)