mirror of https://github.com/docker/cli.git
cmd/docker: don't discard cli.StatusError errors without custom message
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
2f83064ec4
commit
3dd6fc365d
|
@ -48,16 +48,15 @@ func dockerMain() int {
|
|||
otel.SetErrorHandler(debug.OTELErrorHandler)
|
||||
|
||||
if err := runDocker(ctx, dockerCli); err != nil {
|
||||
if sterr, ok := err.(cli.StatusError); ok {
|
||||
if sterr.Status != "" {
|
||||
fmt.Fprintln(dockerCli.Err(), sterr.Status)
|
||||
}
|
||||
var stErr cli.StatusError
|
||||
if errors.As(err, &stErr) {
|
||||
// StatusError should only be used for errors, and all errors should
|
||||
// have a non-zero exit status, so never exit with 0
|
||||
if sterr.StatusCode == 0 {
|
||||
return 1
|
||||
if stErr.StatusCode == 0 { // FIXME(thaJeztah): StatusCode should never be used with a zero status-code. Check if we do this anywhere.
|
||||
stErr.StatusCode = 1
|
||||
}
|
||||
return sterr.StatusCode
|
||||
_, _ = fmt.Fprintln(dockerCli.Err(), stErr)
|
||||
return stErr.StatusCode
|
||||
}
|
||||
if errdefs.IsCancelled(err) {
|
||||
return 0
|
||||
|
|
|
@ -203,7 +203,7 @@ func TestPluginSocketCommunication(t *testing.T) {
|
|||
|
||||
// the plugin does not get signalled, but it does get its
|
||||
// context canceled by the CLI through the socket
|
||||
const expected = "test-socket: exiting after context was done"
|
||||
const expected = "test-socket: exiting after context was done\nexit status 2"
|
||||
actual := strings.TrimSpace(string(out))
|
||||
assert.Check(t, is.Equal(actual, expected))
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue