stty: report write errors instead of panicking (#10552)#13252
stty: report write errors instead of panicking (#10552)#13252PranavRJoshi wants to merge 3 commits into
Conversation
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>
Merging this PR will improve performance by 4.81%
|
| 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)
Footnotes
-
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. ↩
|
GNU testsuite comparison: |
|
We generally define error kinds in an enum using #[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(), "{text}").map_err(SttyError::Write)?; |
Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
|
Done. Refactored into thiserror enum. |
Fixes #10552.
stty > /dev/fullpanicked because allsttyoutput went through theprint!family of macros, which panics when the underlying write tostdoutfails.GNU
sttyreports the error and fails gracefully.Changes:
print!/println!usage insttywith explicit writes tostdoutby introducing a small helper functionwrite_stdout.WrappedPrinter::print/flushand theprint_*functions now returnUResult<()>. Functions that previously returnednix::Resultpropagate their nix errors through the existingFromimpl, so behavior of ioctl/termios failures is unchanged.main.rstouucore::bin!(uu_stty, no_flush), similar to whatcksumalready does.sttynow handles its ownstdoutwrite errors and every output path ends with a newline. This also prevents reporting the same error twice.stty-error-write-errorto US and FR locales.test_write_error_to_dev_full, covering default,--all,--save, andsizeoutput paths.