mirror of
https://github.com/marcoallegretti/karapace.git
synced 2026-03-26 21:43:09 +00:00
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:
parent
7278d9923d
commit
9abbf426bf
1 changed files with 13 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue