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>
@thaJeztah

Copy link
Copy Markdown
Member

Thanks for contributing;

I see your commit message uses your GitHub handle as name for the DCO sign-off;

Signed-off-by: vigneshakaviki <kumarvignesh295@gmail.com>

Can you update the sign-off to use your real name? From CONTRIBUTING.md;

Use your real name (sorry, no pseudonyms or anonymous contributions.)

If you set your user.name and user.email git configs, you can sign your commit automatically with git commit -s.

Can you also remove the Fixes XXX from the commit message? Referencing GitHub tickets from commit messages tends to produce a lot of noise if commits gets merged or cherry-picked;

Fixes: #6973

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see comment above)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error hooks are printed before command output

2 participants