fix(diagnostics): ignore Interrupted and BrokenPipe errors while printing (#5526)

closes #5452
This commit is contained in:
Boshen 2024-09-06 06:38:47 +00:00
parent 7a797ac635
commit fce549e648

View file

@ -1,4 +1,4 @@
use std::io::{BufWriter, Stdout, Write};
use std::io::{BufWriter, ErrorKind, Stdout, Write};
use super::{writer, DiagnosticReporter};
use crate::{Error, GraphicalReportHandler};
@ -16,11 +16,31 @@ impl Default for GraphicalReporter {
impl DiagnosticReporter for GraphicalReporter {
fn finish(&mut self) {
self.writer.flush().unwrap();
self.writer
.flush()
.or_else(|e| {
// Do not panic when the process is skill (e.g. piping into `less`).
if matches!(e.kind(), ErrorKind::Interrupted | ErrorKind::BrokenPipe) {
Ok(())
} else {
Err(e)
}
})
.unwrap();
}
fn render_diagnostics(&mut self, s: &[u8]) {
self.writer.write_all(s).unwrap();
self.writer
.write_all(s)
.or_else(|e| {
// Do not panic when the process is skill (e.g. piping into `less`).
if matches!(e.kind(), ErrorKind::Interrupted | ErrorKind::BrokenPipe) {
Ok(())
} else {
Err(e)
}
})
.unwrap();
}
fn render_error(&mut self, error: Error) -> Option<String> {