Skip to content

fix: flush stderr before printing hooks to ensure correct output order#7053

Open
vigneshakaviki wants to merge 1 commit into
docker:masterfrom
vigneshakaviki:master
Open

fix: flush stderr before printing hooks to ensure correct output order#7053
vigneshakaviki wants to merge 1 commit into
docker:masterfrom
vigneshakaviki:master

Conversation

@vigneshakaviki

Copy link
Copy Markdown

Problem

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:
    Debug this container error with Gordon → docker ai "help me fix this container error"
docker: open ./no-such-file: no such file or directory

This is confusing because the helpful hint appears before the actual error message.

Solution

Added stderr flush before printing hooks to ensure error messages appear in the correct order:

docker: open ./no-such-file: no such file or directory
What's next:
    Debug this container error with Gordon → docker ai "help me fix this container error"

The fix calls Sync() on the stderr file descriptor if available, ensuring all previously buffered output is flushed before hooks are printed.

Testing

  • Existing tests should continue to pass
  • Manual testing with docker run --env-file=./nonexistent confirms hooks now appear after error messages

Fixes: #6973

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: docker#6973
Signed-off-by: vigneshakaviki <kumarvignesh295@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error hooks are printed before command output

1 participant