Skip to content

summarize: Don't panic on broken pipe #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sharnoff
Copy link

I hit #31 while piping summarize to head. The original issue was in part due to prettytable panicking. That's since been upgraded to a version with the fix, but some of the println!s that happen after table.printstd() will also panic from the broken pipe:

$ summarize summarize ... | head
...
thread 'main' panicked at library/std/src/io/stdio.rs:1165:9:
failed printing to stdout: Broken pipe (os error 32)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To fix this, change the println!s to writeln!s, and ignore any errors.

Fixes #31.

I hit rust-lang#31 while piping summarize to head. The original issue was in part
due to `prettytable` panicking. That's since been upgraded to a version
with the fix, but some of the `println!`s that happen after
`table.printstd()` will also panic from the broken pipe:

  $ summarize summarize ... | head
  ...
  thread 'main' panicked at library/std/src/io/stdio.rs:1165:9:
  failed printing to stdout: Broken pipe (os error 32)
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To fix this, change the `println!`s to `writeln!`s, and ignore any
errors.

Fixes rust-lang#31.
@@ -142,7 +142,11 @@ fn diff(opt: DiffOpt) -> Result<(), Box<dyn Error + Send + Sync>> {

table.printstd();

println!("Total cpu time: {:?}", results.total_time);
_ = writeln!(
Copy link
Member

Choose a reason for hiding this comment

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

I think you should just exit the process on a broken pipe rather than keep writing data to nowhere.

Copy link
Author

@sharnoff sharnoff Jun 24, 2025

Choose a reason for hiding this comment

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

Makes sense -- implemented a catch-all "exit on failure" in 59876d9.

Do you think it should special-case broken pipe to return a visible error otherwise? or better to just give up

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.

Summarize panics if piped into head
2 participants