Skip to content

Commit 0eb87bd

Browse files
fix: flush stderr before printing hooks to ensure correct output order
When a command fails and error-hooks are enabled, the hooks were being printed before the command's error message appeared in the output, creating confusing output like: What's next: ... docker: open ./no-such-file: no such file or directory This fix ensures stderr is flushed before printing hooks, so error messages appear in the correct order: docker: open ./no-such-file: no such file or directory What's next: ... Fixes: #6973 Signed-off-by: vigneshakaviki <kumarvignesh295@gmail.com>
1 parent 1d1562e commit 0eb87bd

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

cmd/docker/docker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
546546
// If the command is being executed in an interactive terminal
547547
// and hook are enabled, run the plugin hooks.
548548
if subCommand != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() {
549+
// Ensure stderr is flushed before printing hooks so error messages appear first
550+
if errs, ok := dockerCli.Err().(*os.File); ok {
551+
_ = errs.Sync()
552+
}
549553
pluginmanager.RunCLICommandHooks(ctx, dockerCli, cmd, subCommand, cmdErrorMessage(err))
550554
}
551555

0 commit comments

Comments
 (0)