Flush BufWriters, clean up error reporting#7622
Merged
tertsdiepraam merged 8 commits intouutils:mainfrom Apr 8, 2025
Merged
Conversation
Write errors led with `tr: tr: write error:`.
351a0ec to
a9cd3f1
Compare
|
GNU testsuite comparison: |
We pass a `&mut dyn Write` in anyway, but now that's entirely up to the caller.
|
GNU testsuite comparison: |
Contributor
|
do you know if it impacts performances? thanks |
Contributor
Author
|
There shouldn't be any performance impact. They're already flushed automatically on drop, with this change we flush them manually before dropping so we can handle the errors. The docs say it's "critical" to call flush: https://doc.rust-lang.org/std/io/struct.BufWriter.html |
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.
A
BufWritermust be flushed when you're done with it, since it'll ignore any write errors when it flushes on dropping. So many utilities would ignore write errors for small outputs. I went through all theBufWriters to add this where it was missing. (Exceptshuf, which is handled in #7585.)I also cleaned up some error reporting as I went.
sortused to panic on write errors and some other utilities added weird context to errors or no context at all.All the added flushes have Linux-only tests that use
/dev/full. That seemed the easiest way to do it.