From 1f306758bb6e2d0fadd6bc6fbed45ca6fc8f944d Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Mon, 27 Nov 2023 23:25:30 +0100 Subject: [PATCH] fix: properly handle clap try_parse errors --- components/clarinet-cli/src/frontend/cli.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/clarinet-cli/src/frontend/cli.rs b/components/clarinet-cli/src/frontend/cli.rs index 75c9fa2b0..7d1f92f82 100644 --- a/components/clarinet-cli/src/frontend/cli.rs +++ b/components/clarinet-cli/src/frontend/cli.rs @@ -471,8 +471,14 @@ pub fn main() { )); } } - println!("{}", e); - process::exit(1); + + // handle --version, --help, etc + // see how to safely print clap errors here: + // https://github.com/clap-rs/clap/blob/21b671f689bc0b8d790dc8c42902c22822bf6f82/clap_builder/src/error/mod.rs#L233 + let _ = e.print(); + let _ = std::io::stdout().lock().flush(); + let _ = std::io::stderr().lock().flush(); + std::process::exit(e.exit_code()); } };