Skip to content

stty: report write errors instead of panicking (#10552)#13252

Open
PranavRJoshi wants to merge 3 commits into
uutils:mainfrom
PranavRJoshi:stty-10552
Open

stty: report write errors instead of panicking (#10552)#13252
PranavRJoshi wants to merge 3 commits into
uutils:mainfrom
PranavRJoshi:stty-10552

Conversation

@PranavRJoshi

Copy link
Copy Markdown

Fixes #10552.

stty > /dev/full panicked because all stty output went through the print! family of macros, which panics when the underlying write to stdout fails.

GNU stty reports the error and fails gracefully.

Changes:

  • Replaced all print!/println! usage in stty with explicit writes to stdout by introducing a small helper function write_stdout.
  • WrappedPrinter::print/flush and the print_* functions now return UResult<()>. Functions that previously returned nix::Result propagate their nix errors through the existing From impl, so behavior of ioctl/termios failures is unchanged.
  • Switched main.rs to uucore::bin!(uu_stty, no_flush), similar to what cksum already does. stty now handles its own stdout write errors and every output path ends with a newline. This also prevents reporting the same error twice.
  • Added stty-error-write-error to US and FR locales.
  • Added a Linux-gated regression test test_write_error_to_dev_full, covering default, --all, --save, and size output paths.

stty panicked when writing to stdout failed because all output went
through the 'print!' family of macros, which panics on I/O errors.

Replace the macros with explicit writes to stdout and propagate failures
as UResult, mapping them with a localized "write error" so behavior
matches GNU stty with exit code 1. Functions previously returning
nix::Result now returns UResult as nix errors convert through the
existing From impl, so their behavior is unchanged.

Lastly, opt out of uucore's exit-time stdout flush since stty now
reports its own write errors and every output path ends with a newline.
The extra flush would otherwise report the same error twice.

Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
@codspeed-hq

codspeed-hq Bot commented Jul 2, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 4.81%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 330 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation sort_ascii_utf8_locale 16.1 ms 15.4 ms +4.81%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing PranavRJoshi:stty-10552 (50935c4) with main (eae191c)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.

@xtqqczze

xtqqczze commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

We generally define error kinds in an enum using thiserror crate, something like:

#[derive(Debug, Error)]
pub enum SttyError {
    #[error("{}: {}", translate!("stty-error-write"), strip_errno(.0))]
    Write(io::Error),
}

Then maybe we wouldn't need the write_stdout function and could just do:

write!(stdout(), "{text}").map_err(SttyError::Write)?;

@PranavRJoshi

Copy link
Copy Markdown
Author

Done. Refactored into thiserror enum.

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.

stty > /dev/full panics

2 participants