fix: handle write errors gracefully instead of panicking on /dev/full#7
Open
SAY-5 wants to merge 2 commits intouutils:mainfrom
Open
fix: handle write errors gracefully instead of panicking on /dev/full#7SAY-5 wants to merge 2 commits intouutils:mainfrom
SAY-5 wants to merge 2 commits intouutils:mainfrom
Conversation
Replace println! with writeln!(io::stdout(), ...) and handle BrokenPipe silently, other I/O errors via stderr + exit 1. Matches the uutils convention used in coreutils' true.rs. Fixes uutils#5 Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
oech3
reviewed
May 5, 2026
| println!("---\n{ast}"); | ||
| // Avoid `println!`, which panics on broken pipe / ENOSPC (e.g. `>/dev/full`). | ||
| // Match the uutils convention: silently exit on BrokenPipe, report other I/O | ||
| // errors to stderr and exit with failure. |
Contributor
There was a problem hiding this comment.
We would do same things at anywhere. So the comment is not needed.
We should ayto-detect usage of (e)print(ln)! at CI instead.
Collaborator
There was a problem hiding this comment.
Relevant:
- https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout
- https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr
We can set those lints once we get rid of the macros.
oech3
reviewed
May 5, 2026
| // Match the uutils convention: silently exit on BrokenPipe, report other I/O | ||
| // errors to stderr and exit with failure. | ||
| if let Err(e) = writeln!(io::stdout(), "---\n{ast}") { | ||
| if e.kind() == io::ErrorKind::BrokenPipe { |
Contributor
There was a problem hiding this comment.
Would you avoid collapsible_if and if let ... = ... && instead?
Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
Author
|
Done — replaced the print macros with structured logging. |
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.
Fixes #5.
println!panics if the underlying write fails (e.g.>/dev/fullreturns ENOSPC, or stdout is a closed pipe). Replaced it withwriteln!(io::stdout(), ...), returning silently onBrokenPipeand reporting other I/O errors to stderr with exit code 1 — matching the convention used incoreutils/src/uu/true/src/true.rs.Added a Linux-gated regression test that pipes stdout to
/dev/fulland asserts the process does not panic (exit code != 2).