Skip to content
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

Broken pipe (os error 32) when piping output to head #16

Closed
gingkapls opened this issue Nov 23, 2020 · 2 comments
Closed

Broken pipe (os error 32) when piping output to head #16

gingkapls opened this issue Nov 23, 2020 · 2 comments
Labels
bug Something isn't working done Issue is fixed

Comments

@gingkapls
Copy link

gingkapls commented Nov 23, 2020

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

shows up sometimes whenever I pipe the output of flavours info $(flavours current) using head like this

flavours info $(flavours current) | head -n<integer>

The command works fine and the error can be avoided by redirecting it to /dev/null but thought I'd let you know just in case.

also running with env variable RUST_BACKTRACE=1 doesn't provide a backtrace

@Misterio77
Copy link
Owner

Misterio77 commented Nov 24, 2020

Hmmm this seems to be a problem with the print macro in Rust.

Apparently, head closes the stream when it's done receiving the specified number of lines, which raises an Err. println! then unwraps that Result instead of moving it up, causing a panic instead of returning a Result i can handle to gracefully close the program.

Long story short, writing to stdout can fail and the widely used print feature Rust has won't handle it.

It seems the way to go would be replacing print!s with write!s, which do propagate Results.

The possible workarounds seem to be your /dev/null piping, or piping flavours info through cat before piping it to head.

I'll probably get to it in the next few days/weeks, but feel free to write a patch if you have the time to spare ❤

@Misterio77 Misterio77 added the bug Something isn't working label Nov 24, 2020
@Misterio77 Misterio77 added the todo Just needs to be fixed label Dec 3, 2020
@Misterio77
Copy link
Owner

This should be fixed in the commit d958a60. I'll push a new release soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working done Issue is fixed
Projects
None yet
Development

No branches or pull requests

2 participants