Skip to content

Commit

Permalink
fix(cli): Fix broken pipe error for JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
tingerrr committed Aug 7, 2024
1 parent 830b250 commit 9d94ee2
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions crates/typst-test-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,28 @@ fn main() -> ExitCode {
match ctx.run() {
Ok(()) => {}
Err(_) if ctx.is_operation_failure() => {}
// NOTE: we ignore broken pipes as these occur when programs close the
// pipe before we're done writing
Err(err)
if err
.root_cause()
Err(err) => 'err: {
let root = err.root_cause();

// FIXME: https://github.com/serde-rs/json/issues/1169
// NOTE: we can't access the inner io error itself, but at least the
// kind
if root.downcast_ref().is_some_and(|err: &serde_json::Error| {
err.io_error_kind()
.is_some_and(|kind| kind == io::ErrorKind::BrokenPipe)
}) {
break 'err;
}

// NOTE: we ignore broken pipes as these occur when programs close
// the pipe before we're done writing
if root
.downcast_ref()
.is_some_and(|err: &io::Error| err.kind() == io::ErrorKind::BrokenPipe) => {}
Err(err) => {
.is_some_and(|err: &io::Error| err.kind() == io::ErrorKind::BrokenPipe)
{
break 'err;
}

ctx.unexpected_error(|r| {
r.ui().error_with(|w| {
writeln!(
Expand Down

0 comments on commit 9d94ee2

Please sign in to comment.