From 92c974d0669cb046148206139f3fb9378f1c4a3a Mon Sep 17 00:00:00 2001 From: arnavb11 Date: Fri, 11 Jan 2019 14:17:01 +0000 Subject: [PATCH] Handle clap errors and other errors separately --- src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index b59cab8..bc522ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -270,9 +270,12 @@ fn main() { let result = run(); if let Err(err) = result { - // The whitespace is being removed from the right because - // clap errors add a newline to the end of the output already - eprintln!("Error: {}", format!("{}", err).trim_right()); - std::process::exit(1); + if let Some(clap_err) = err.downcast_ref::() { + eprint!("{}", clap_err); // Clap errors already have newlines + std::process::exit(1); + } else { + eprintln!("Error: {}", err); + std::process::exit(1); + } } }