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 908bf8e
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions crates/typst-test-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::error::Error;
use std::io;
use std::io::{IsTerminal, Write};
use std::process::ExitCode;
Expand Down Expand Up @@ -97,14 +98,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 908bf8e

Please sign in to comment.