doy / rbw

unofficial bitwarden cli
https://git.tozt.net/rbw
Other
611 stars 84 forks source link

panic when piping to `head` #79

Closed Witcher01 closed 1 year ago

Witcher01 commented 2 years ago

Piping the output of rbw list to head results in a panic:

$ rbw list | head -n 1
<first entry>
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:935:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Piping it into tail doesn't produce a panic, probably due to the pipe being closed after instead of before rbw is done writing to it.

I haven't looked into it much, but this instance of the panic seems to be cause by the following println! macro call: https://github.com/doy/rbw/blob/94a0009fc2067bab549b194ca976a71e7395f403/src/bin/rbw/commands.rs#L533

A fix would be to replace this with a write!, which returns an error that can be handled.

If a fix is desired I might have time to look into it.

doy commented 2 years ago

yeah, fixing this seems like a good idea - feel free to submit a pull request!