fix: flush stderr before printing hooks to ensure correct output order#7053
Open
vigneshakaviki wants to merge 1 commit into
Open
fix: flush stderr before printing hooks to ensure correct output order#7053vigneshakaviki wants to merge 1 commit into
vigneshakaviki wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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:
The fix calls
Sync()on the stderr file descriptor if available, ensuring all previously buffered output is flushed before hooks are printed.Testing
docker run --env-file=./nonexistentconfirms hooks now appear after error messagesFixes: #6973