Skip to content

Commit 3dd6fc3

Browse files
committed
cmd/docker: don't discard cli.StatusError errors without custom message
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 2f83064 commit 3dd6fc3

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

cmd/docker/docker.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ func dockerMain() int {
4848
otel.SetErrorHandler(debug.OTELErrorHandler)
4949

5050
if err := runDocker(ctx, dockerCli); err != nil {
51-
if sterr, ok := err.(cli.StatusError); ok {
52-
if sterr.Status != "" {
53-
fmt.Fprintln(dockerCli.Err(), sterr.Status)
54-
}
51+
var stErr cli.StatusError
52+
if errors.As(err, &stErr) {
5553
// StatusError should only be used for errors, and all errors should
5654
// have a non-zero exit status, so never exit with 0
57-
if sterr.StatusCode == 0 {
58-
return 1
55+
if stErr.StatusCode == 0 { // FIXME(thaJeztah): StatusCode should never be used with a zero status-code. Check if we do this anywhere.
56+
stErr.StatusCode = 1
5957
}
60-
return sterr.StatusCode
58+
_, _ = fmt.Fprintln(dockerCli.Err(), stErr)
59+
return stErr.StatusCode
6160
}
6261
if errdefs.IsCancelled(err) {
6362
return 0

e2e/cli-plugins/socket_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func TestPluginSocketCommunication(t *testing.T) {
203203

204204
// the plugin does not get signalled, but it does get its
205205
// context canceled by the CLI through the socket
206-
const expected = "test-socket: exiting after context was done"
206+
const expected = "test-socket: exiting after context was done\nexit status 2"
207207
actual := strings.TrimSpace(string(out))
208208
assert.Check(t, is.Equal(actual, expected))
209209
})

0 commit comments

Comments
 (0)