cksum: get rid of print! and println! to avoid panicking on write errors#12099
cksum: get rid of print! and println! to avoid panicking on write errors#12099RenjiSann wants to merge 2 commits intouutils:mainfrom
print! and println! to avoid panicking on write errors#12099Conversation
|
GNU testsuite comparison: |
| digest_output.write_raw(io::stdout())?; | ||
| digest_output | ||
| .write_raw(&mut w) | ||
| .map_err_context(|| "write error".into())?; |
There was a problem hiding this comment.
| .map_err_context(|| "write error".into())?; | |
| .map_err_context(|| translate!("checksum-error-write"))?; |
string should be localized
There was a problem hiding this comment.
Done 👍
I've also created a shorthand function to centralize all calls to this .map_err_context(|| "write error".into()).
There was a problem hiding this comment.
I guess I'd prefer something more idiomatic like:
res.map_err(ChecksumError::Write)possible implementation:
pub enum ChecksumError {
...
#[error("{}", translate!("common-write-error", "error" => strip_errno(.0)))]
Write(io::Error),
}355ddc8 to
ad9b814
Compare
Merging this PR will degrade performance by 16.95%
Performance Changes
Comparing Footnotes
|
ad9b814 to
c73b690
Compare
|
Note that GNU seems to inconsistenly handle whether it shows the I assume this is because the way the error is displayed is different between the writes and the final flush that happens in $ uu_cksum /dev/null > /dev/full
cksum: write error: No space left on device
$ gnu_cksum /dev/null > /dev/full
cksum: write error # <-- GNU most probably prints the error differently here
$ uu_cksum /dev/null > /dev/full -z
cksum: write error: No space left on device
$ gnu_cksum /dev/null > /dev/full -z
cksum: write error: No space left on device |
maybe you should report that to the coreutils/coreutils repo |
| return Ok(()); | ||
| } | ||
| // Flush the writer if we didn't write newlines. | ||
| w.flush().map_err(|e| ChecksumError::Write(e).into()) |
There was a problem hiding this comment.
| w.flush().map_err(|e| ChecksumError::Write(e).into()) | |
| w.flush().map_err(ChecksumError::Write)?; | |
| Ok(()) |
nitpick: I'm fine with it either way
Good work with the macros, I'd been wondering whether it was possible to avoid that flush. |
c73b690 to
104bdfe
Compare
| } | ||
|
|
||
| if options.line_ending != LineEnding::Newline { | ||
| // Flush the writer if we didn't write newlines. |
There was a problem hiding this comment.
I guess the comment is redundant now
Done ! coreutils/coreutils#258
Thanks :) |
... To avoid duplicate error message when the util already does the job
104bdfe to
7e4e632
Compare
Fix for #10947
Also needed to do some shenanigans in the
uucore::binmacro to avoid having an extra flush failing.