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)
|
otel.SetErrorHandler(debug.OTELErrorHandler)
|
||||||
|
|
||||||
if err := runDocker(ctx, dockerCli); err != nil {
|
if err := runDocker(ctx, dockerCli); err != nil {
|
||||||
if sterr, ok := err.(cli.StatusError); ok {
|
var stErr cli.StatusError
|
||||||
if sterr.Status != "" {
|
if errors.As(err, &stErr) {
|
||||||
fmt.Fprintln(dockerCli.Err(), sterr.Status)
|
|
||||||
}
|
|
||||||
// StatusError should only be used for errors, and all errors should
|
// StatusError should only be used for errors, and all errors should
|
||||||
// have a non-zero exit status, so never exit with 0
|
// have a non-zero exit status, so never exit with 0
|
||||||
if sterr.StatusCode == 0 {
|
if stErr.StatusCode == 0 { // FIXME(thaJeztah): StatusCode should never be used with a zero status-code. Check if we do this anywhere.
|
||||||
return 1
|
stErr.StatusCode = 1
|
||||||
}
|
}
|
||||||
return sterr.StatusCode
|
_, _ = fmt.Fprintln(dockerCli.Err(), stErr)
|
||||||
|
return stErr.StatusCode
|
||||||
}
|
}
|
||||||
if errdefs.IsCancelled(err) {
|
if errdefs.IsCancelled(err) {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -203,7 +203,7 @@ func TestPluginSocketCommunication(t *testing.T) {
|
||||||
|
|
||||||
// the plugin does not get signalled, but it does get its
|
// the plugin does not get signalled, but it does get its
|
||||||
// context canceled by the CLI through the socket
|
// 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))
|
actual := strings.TrimSpace(string(out))
|
||||||
assert.Check(t, is.Equal(actual, expected))
|
assert.Check(t, is.Equal(actual, expected))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue