cli: exit cleanly on broken pipe

Piping CLI output into tools like head may close stdout early.
Rust then panics when printing.

Install a panic hook that exits successfully on EPIPE instead of
emitting a panic backtrace.
This commit is contained in:
Marco Allegretti 2026-02-24 11:46:51 +01:00
parent 7278d9923d
commit 9abbf426bf

View file

@ -212,6 +212,19 @@ enum Commands {
#[allow(clippy::too_many_lines)]
fn main() -> ExitCode {
let default_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
let msg = info.to_string();
if msg.contains("Broken pipe")
|| msg.contains("broken pipe")
|| msg.contains("os error 32")
|| msg.contains("failed printing to stdout")
{
std::process::exit(0);
}
default_hook(info);
}));
let cli = Cli::parse();
let default_level = if cli.trace {