Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle BrokenPipe gracefully #60

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/bin/ion/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@ mod commands;
use crate::commands::beta::BetaNamespace;
use anyhow::Result;
use commands::IonCliCommand;
use ion_rs::IonError;
use std::io::ErrorKind;

use crate::commands::dump::DumpCommand;

fn main() -> Result<()> {
let root_command = RootCommand;
let args = root_command.clap_command().get_matches();
let mut command_path: Vec<String> = vec![root_command.name().to_owned()];
root_command.run(&mut command_path, &args)

if let Err(e) = root_command.run(&mut command_path, &args) {
match e.downcast_ref::<IonError>() {
// If `ion-cli` is being invoked as part of a pipeline we want to allow the pipeline to
// to shut off without printing an error to stderr
Some(IonError::IoError { source }) if source.kind() == ErrorKind::BrokenPipe => {
return Ok(())
}
_ => return Err(e),
}
};

Ok(())
}

pub struct RootCommand;
Expand Down
Loading