Closed arcstur closed 3 months ago
This seems to be the source of the issue https://github.com/rust-lang/rust/issues/46016
I see, makes sense! But I think it's still better to use writeln! than println! in the loop, right?
Yeah I was just curious about the source of the problem.
Could you share what you're piping toggl list
to?
This is the my comparison of main and your pr
When piping to head it panics for me:
toggl list | head
... # my time entries
thread 'main' panicked at library/std/src/io/stdio.rs:1030:9:
failed printing to stdout: Broken pipe (os error 32)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Hmm I can't reproduce the panic on main
But I'm good with the fix if it works for you. For reference what operating system / arch are you using?
I think that's becasuse you have only a few items in there. It panicks when there are more than head
needs. If I do head -n 100 it does not panic. Try doing toggl list | head -1
I'm using Arch 6.9.1-arch1-1
With head -1
Piping the output of
toggl list
would panic, probably because of calling println! in a loop, which we should not do:https://rust-cli.github.io/book/tutorial/output.html#a-note-on-printing-performance
I updated the list command code to use a BufWriter and
writeln!
. I usedexpect
to deal with writeln errors. I think we could have an error type in the future that absorbsio::Error
, what do you think?Anyway, with this the list command stopped panicking when piping.