Skip to content

Commit

Permalink
fix(diagnostics): ignore Interrupted and BrokenPipe errors while …
Browse files Browse the repository at this point in the history
…printing (#5526)

closes #5452
  • Loading branch information
Boshen committed Sep 6, 2024
1 parent 7a797ac commit fce549e
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions crates/oxc_diagnostics/src/reporter/graphical.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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> {
Expand Down

0 comments on commit fce549e

Please sign in to comment.