Skip to content

Commit

Permalink
Merge pull request #60 from amazon-ion/broken-pipe
Browse files Browse the repository at this point in the history
Handle BrokenPipe gracefully
  • Loading branch information
jobarr-amzn authored Aug 22, 2023
2 parents 968187a + 4f7c981 commit 2f1fa56
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 2f1fa56

Please sign in to comment.