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:
Sebastiaan van Stijn 2024-07-04 19:20:59 +02:00
parent 2f83064ec4
commit 3dd6fc365d
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 7 additions and 8 deletions

View File

@ -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

View File

@ -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))
})