mirror of https://github.com/docker/cli.git
Merge pull request #5231 from thaJeztah/prettier_exit_status
cli: make cli.StatusError slightly prettier
This commit is contained in:
commit
cad08ff3b1
|
@ -90,7 +90,7 @@ func TestNetworkRemoveForce(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Contains(fakeCli.ErrBuffer().String(), tc.expectedErr))
|
assert.Check(t, is.Contains(fakeCli.ErrBuffer().String(), tc.expectedErr))
|
||||||
assert.ErrorContains(t, err, "Code: 1")
|
assert.ErrorContains(t, err, "exit status 1")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -444,7 +444,7 @@ func TestFormatInfo(t *testing.T) {
|
||||||
{
|
{
|
||||||
doc: "syntax",
|
doc: "syntax",
|
||||||
template: "{{}",
|
template: "{{}",
|
||||||
expectedError: `Status: template parsing error: template: :1: unexpected "}" in command, Code: 64`,
|
expectedError: `template parsing error: template: :1: unexpected "}" in command`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
doc: "syntax",
|
doc: "syntax",
|
||||||
|
|
10
cli/error.go
10
cli/error.go
|
@ -1,7 +1,7 @@
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,6 +28,12 @@ type StatusError struct {
|
||||||
StatusCode int
|
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 {
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue