From 72ab8811c34502fbcfd34db76dd253fd798ef119 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Tue, 22 Apr 2025 00:05:29 +0200 Subject: [PATCH] Ignore broken pipe error when printing dictionary stdout closing prematurely is normal behaviour, e.g. piping into `head`. --- crates/dtmt/src/cmd/dictionary.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/dtmt/src/cmd/dictionary.rs b/crates/dtmt/src/cmd/dictionary.rs index 62a5295..4c54c34 100644 --- a/crates/dtmt/src/cmd/dictionary.rs +++ b/crates/dtmt/src/cmd/dictionary.rs @@ -227,9 +227,12 @@ pub(crate) async fn run(mut ctx: sdk::Context, matches: &ArgMatches) -> Result<( let lookup = &ctx.lookup; let rows: Vec<_> = lookup.entries().iter().map(TableRow::from).collect(); - print_stdout(rows.with_title())?; - - Ok(()) + match print_stdout(rows.with_title()) { + Ok(_) => Ok(()), + // Closing stdout prematurely is normal behavior with things like piping into `head` + Err(err) if err.kind() == std::io::ErrorKind::BrokenPipe => Ok(()), + Err(err) => Err(err.into()), + } } _ => unreachable!( "clap is configured to require a subcommand, and they're all handled above"