Skip to content

Commit 350a0b6

Browse files
committed
cli-plugins: Run(): don't discard cli.StatusError errors without message
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 3dd6fc3 commit 350a0b6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cli-plugins/plugin/plugin.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package plugin
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"os"
89
"sync"
@@ -92,18 +93,17 @@ func Run(makeCmd func(command.Cli) *cobra.Command, meta manager.Metadata) {
9293
plugin := makeCmd(dockerCli)
9394

9495
if err := RunPlugin(dockerCli, plugin, meta); err != nil {
95-
if sterr, ok := err.(cli.StatusError); ok {
96-
if sterr.Status != "" {
97-
fmt.Fprintln(dockerCli.Err(), sterr.Status)
98-
}
96+
var stErr cli.StatusError
97+
if errors.As(err, &stErr) {
9998
// StatusError should only be used for errors, and all errors should
10099
// have a non-zero exit status, so never exit with 0
101-
if sterr.StatusCode == 0 {
102-
os.Exit(1)
100+
if stErr.StatusCode == 0 { // FIXME(thaJeztah): this should never be used with a zero status-code. Check if we do this anywhere.
101+
stErr.StatusCode = 1
103102
}
104-
os.Exit(sterr.StatusCode)
103+
_, _ = fmt.Fprintln(dockerCli.Err(), stErr)
104+
os.Exit(stErr.StatusCode)
105105
}
106-
fmt.Fprintln(dockerCli.Err(), err)
106+
_, _ = fmt.Fprintln(dockerCli.Err(), err)
107107
os.Exit(1)
108108
}
109109
}

0 commit comments

Comments
 (0)