mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Handle broken pipe errors on stdout gracefully
Replace `println!` calls on the results paths with `writeln!` on `io::stdout()` and propagate the `io::Error` to `main`, where `ErrorKind::BrokenPipe` is turned into a quiet `exit(0)`. This matches the conventional behavior of command-line tools when their output pipe is closed early (e.g. `hyperfine ... | head -n 0`), and fixes panics in all run-output paths: the per-benchmark header and results, the speed comparison summary, and `-`-style exports to stdout. The warnings and "Note" outputs to stderr are converted the same way. The earlier fix for #453 only covered the `-h`/`--help` output. A regression test runs hyperfine with a pre-closed stdout pipe. Assisted-by: AI tooling (patch generated and verified automatically)
This commit is contained in:
1 parent
4d073e08ae
commit
47339b0862
5 files changed
+104
-30
No files matched your search
+3
-3
@@ -1,5 +1,5 @@
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::Write;
|
||||
use std::io::{self, Write};
|
||||
|
||||
mod asciidoc;
|
||||
mod csv;
|
||||
@@ -144,8 +144,8 @@ impl ExportManager {
|
||||
}
|
||||
ExportTarget::Stdout => {
|
||||
if !intermediate {
|
||||
println!();
|
||||
println!("{}", String::from_utf8(content()?).unwrap());
|
||||
writeln!(io::stdout())?;
|
||||
writeln!(io::stdout(), "{}", String::from_utf8(content()?).unwrap())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user