Skip to content

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

Merged
Alonely0 merged 2 commits into
uutils:mainfrom
SAY-5:fix/awk-write-error-dev-full-5
May 7, 2026
Merged

fix: handle write errors gracefully instead of panicking on /dev/full#7
Alonely0 merged 2 commits into
uutils: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.

@Alonely0
Copy link
Copy Markdown
Collaborator

Alonely0 commented May 7, 2026

Seems okay to me. Ty for the contribution! I'll do a follow-up commit later to integrate this with ariadne, though.

@Alonely0 Alonely0 merged commit 18d5de2 into uutils:main May 7, 2026
9 checks passed
@oech3
Copy link
Copy Markdown
Contributor

oech3 commented May 8, 2026

It seems @SAY-5 does not appear as contributor by unknown reason on top page.

@Alonely0
Copy link
Copy Markdown
Collaborator

Alonely0 commented May 8, 2026

It seems @SAY-5 does not appear as contributor by unknown reason on top page.

Weird. If I had to guess, it could be because their commit email does not match their GitHub's, as their profile does not pop up on their commits. Elsewhere, maybe it's related to yesterday's outage, so we could ping support. @SAY-5 Can you verify the email here 18d5de2 is added to your account? If not, do so if you want GitHub to credit your work.

@SAY-5
Copy link
Copy Markdown
Author

SAY-5 commented May 8, 2026

Following up here: the merged commit now resolves to @SAY-5 on the commit page (18d5de2ffee3f345285290c733b51deb80e7aad7), so the attribution link is in place now. The sign-off on that commit is saiasish.cnp@gmail.com; if the contribution graph or top-page credit was lagging before, it may have been a temporary GitHub-side delay.

@Alonely0
Copy link
Copy Markdown
Collaborator

Alonely0 commented May 8, 2026

Probably. It's now happening to oech3's latest commit as well, so it seems GitHub is not resolving authorship on fast-forwarded contributions properly...

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