fix: Swallow broken pipes

Previously, we paniced.  This is one less reason people have to call
lower level `get_matches` to get the commonly expected behavior, making
it more likely for the Rust community to "do the right thing"

Fixes #2659
This commit is contained in:
Ed Page 2021-08-18 10:16:55 -05:00
parent a4137d639a
commit 329fe4a24b

View file

@ -478,11 +478,13 @@ impl Error {
/// or prints to `stdout` and exits with a status of `0`. /// or prints to `stdout` and exits with a status of `0`.
pub fn exit(&self) -> ! { pub fn exit(&self) -> ! {
if self.use_stderr() { if self.use_stderr() {
self.message.print().expect("Error writing Error to stderr"); // Swallow broken pipe errors
let _ = self.message.print();
safe_exit(USAGE_CODE); safe_exit(USAGE_CODE);
} }
self.message.print().expect("Error writing Error to stdout"); // Swallow broken pipe errors
let _ = self.message.print();
safe_exit(SUCCESS_CODE) safe_exit(SUCCESS_CODE)
} }