tsort: handle stdout write errors without panicking#12065
tsort: handle stdout write errors without panicking#12065dragutreis wants to merge 1 commit intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
Merging this PR will not alter performance
Comparing Footnotes
|
| } | ||
|
|
||
| g.run_tsort(); | ||
| g.run_tsort().map_err(|e| USimpleError::new(1, format!("write error: {e}")))?; |
There was a problem hiding this comment.
I guess it would be better if run_tsort returned Result<(), TsortError> instead
| g.run_tsort().map_err(|e| USimpleError::new(1, format!("write error: {e}")))?; | |
| g.run_tsort()?; |
You'd need to add a TsortError variant:
#[error("{}", translate!("tsort-error-write", "error" => strip_errno(.0)))]
Write(io::Error),and update src/uu/tsort/locales/en-US.ftl, src/uu/tsort/locales/en-FR.ftl
There was a problem hiding this comment.
Alright, will do, thanks for the suggestion.
| /// Wrapper for bubbling up IO errors | ||
| #[error("{0}")] | ||
| IO(#[from] io::Error), |
There was a problem hiding this comment.
| /// Wrapper for bubbling up IO errors | |
| #[error("{0}")] | |
| IO(#[from] io::Error), |
is it unused?
There was a problem hiding this comment.
Seems like it, lemme double check 1 sec.
There was a problem hiding this comment.
I may have made a mistake, I messed up my local branch state while testing the suggestion. Pushed to the PR on accident.
There was a problem hiding this comment.
at this point you probably want to rebase to fixup the history, feel free to add me as co-author :)
01918ef to
60be635
Compare
| IO(#[from] io::Error), | ||
| /// Read error. | ||
| #[error("{}", translate!("tsort-error-read", "error" => strip_errno(.0)))] | ||
| Read(io::Error), |
There was a problem hiding this comment.
nit: separate with newline (amend last commit)
Co-authored-by: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Co-authored-by: oech3 <79379754+oech3@users.noreply.github.com>
60be635 to
cf31a00
Compare
Fixes #12006
Avoid a panic in tsort when stdout is unwritable (for example, redirected to /dev/full). Previously an unchecked println! was used which could panic on write errors. Replaced that with a writeln! wrapped in error handling so the program continues generating cycle diagnostics even if writing to stdout fails.
Cycle diagnostics are still always written to stderr; any write errors are recorded and cause the program to exit with status 1 after processing completes.
Tested with
/etc/pacman.confandprintf "a b\nb a\n" | tsort > /dev/fullin both cases.