Skip to content

fix: handle write errors gracefully instead of panicking on /dev/full#7

Open
SAY-5 wants to merge 2 commits intouutils:mainfrom
SAY-5:fix/awk-write-error-dev-full-5
Open

fix: handle write errors gracefully instead of panicking on /dev/full#7
SAY-5 wants to merge 2 commits intouutils:mainfrom
SAY-5:fix/awk-write-error-dev-full-5

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 5, 2026

Fixes #5.

println! panics if the underlying write fails (e.g. >/dev/full returns ENOSPC, or stdout is a closed pipe). Replaced it with writeln!(io::stdout(), ...), returning silently on BrokenPipe and reporting other I/O errors to stderr with exit code 1 — matching the convention used in coreutils/src/uu/true/src/true.rs.

Added a Linux-gated regression test that pipes stdout to /dev/full and asserts the process does not panic (exit code != 2).

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>
Comment thread src/main.rs Outdated
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/main.rs Outdated
// 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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you avoid collapsible_if and if let ... = ... && instead?

Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
@SAY-5
Copy link
Copy Markdown
Author

SAY-5 commented May 6, 2026

Done — replaced the print macros with structured logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

awk "BEGIN { print 1 }" >/dev/full panics

3 participants