rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

rustfmt --check: handle writing to a broken pipe gracefully

Open bertschingert opened this issue 1 year ago • 1 comments

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.

bertschingert avatar Jan 09 '24 04:01 bertschingert

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.

Screen Shot 2024-01-24 at 9 53 01 PM

ytmimi avatar Jan 25 '24 02:01 ytmimi