Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cmd/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,20 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
// If the command is being executed in an interactive terminal
// and hook are enabled, run the plugin hooks.
if subCommand != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() {
pluginmanager.RunCLICommandHooks(ctx, dockerCli, cmd, subCommand, cmdErrorMessage(err))
errMessage := cmdErrorMessage(err)

// If the command produced an error that has yet to be printed,
// print it before running hooks, so that hook output (such as
// "What's next" hints) is shown after the error message instead
// of before it. The error is replaced with a silent error that
// only carries the exit-code, so that main does not print the
// error a second time.
if err != nil && !errdefs.IsCanceled(err) && err.Error() != "" {
_, _ = fmt.Fprintln(dockerCli.Err(), err)
err = cli.StatusError{StatusCode: getExitCode(err)}
}

pluginmanager.RunCLICommandHooks(ctx, dockerCli, cmd, subCommand, errMessage)
}

return err
Expand Down