From ca29e4760c07e94a87dd550e9359dac57dac4e72 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 30 Oct 2021 09:26:07 -0500 Subject: [PATCH] chore(error): Remove unused backtrace warning Technically, this also fixes a bug with an extra newline when building with `debug` but that is a pretty minor cosmetic issue. It is unclear if `backtrace` has a trailing newline or not, so I left that as-is. --- src/parse/errors.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/parse/errors.rs b/src/parse/errors.rs index 2fc5900c..ec3108d5 100644 --- a/src/parse/errors.rs +++ b/src/parse/errors.rs @@ -439,21 +439,17 @@ pub struct Error { pub info: Vec, pub(crate) source: Option>, wait_on_exit: bool, - backtrace: Backtrace, + backtrace: Option, } impl Display for Error { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - #[cfg(feature = "debug")] - { - writeln!(f, "{}", self.message.formatted())?; + // Assuming `self.message` already has a trailing newline, from `try_help` or similar + write!(f, "{}", self.message.formatted())?; + if let Some(backtrace) = self.backtrace.as_ref() { writeln!(f)?; writeln!(f, "Backtrace:")?; - writeln!(f, "{}", self.backtrace)?; - } - #[cfg(not(feature = "debug"))] - { - Display::fmt(&self.message.formatted(), f)?; + writeln!(f, "{}", backtrace)?; } Ok(()) } @@ -1182,8 +1178,8 @@ struct Backtrace(backtrace::Backtrace); #[cfg(feature = "debug")] impl Backtrace { - fn new() -> Self { - Self(backtrace::Backtrace::new()) + fn new() -> Option { + Some(Self(backtrace::Backtrace::new())) } } @@ -1201,8 +1197,8 @@ struct Backtrace; #[cfg(not(feature = "debug"))] impl Backtrace { - fn new() -> Self { - Self + fn new() -> Option { + None } }