rustfmt
rustfmt copied to clipboard
rustfmt --check: handle writing to a broken pipe gracefully
this addresses a panic when rustfmt --check
makes a write()
call that fails. There have been a few issues that already discussed this:
https://github.com/rust-lang/rustfmt/issues/5114 https://github.com/rust-lang/rustfmt/issues/2926
On one of the issues it was noted that it would be difficult to hit this outside of contrived situations like piping to "false", but I think it really is pretty easy to hit -- I got this panic by accidentally making a typo in "less", and piping to "les":
rustfmt --check prog.rs | les
With this patch I opted to leave the panic behavior in place for any write errors other than EPIPE, so that the tool's behavior is unchanged except in this specific situation. However, it could be preferable to take the opportunity to remove the panics entirely and handle all write errors gracefully. I can update the patch to not panic at all on write errors, if others agree.
Probably better not to panic!
. Also, I think the tests are failing because you need to run rustfmt on itself 😅. The self_test
makes sure that rustfmt is formatted properly.