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.
This commit is contained in:
Ed Page 2021-10-30 09:26:07 -05:00
parent b42e2baf59
commit ca29e4760c

View file

@ -439,21 +439,17 @@ pub struct Error {
pub info: Vec<String>, pub info: Vec<String>,
pub(crate) source: Option<Box<dyn error::Error + Send + Sync>>, pub(crate) source: Option<Box<dyn error::Error + Send + Sync>>,
wait_on_exit: bool, wait_on_exit: bool,
backtrace: Backtrace, backtrace: Option<Backtrace>,
} }
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
#[cfg(feature = "debug")] // Assuming `self.message` already has a trailing newline, from `try_help` or similar
{ write!(f, "{}", self.message.formatted())?;
writeln!(f, "{}", self.message.formatted())?; if let Some(backtrace) = self.backtrace.as_ref() {
writeln!(f)?; writeln!(f)?;
writeln!(f, "Backtrace:")?; writeln!(f, "Backtrace:")?;
writeln!(f, "{}", self.backtrace)?; writeln!(f, "{}", backtrace)?;
}
#[cfg(not(feature = "debug"))]
{
Display::fmt(&self.message.formatted(), f)?;
} }
Ok(()) Ok(())
} }
@ -1182,8 +1178,8 @@ struct Backtrace(backtrace::Backtrace);
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
impl Backtrace { impl Backtrace {
fn new() -> Self { fn new() -> Option<Self> {
Self(backtrace::Backtrace::new()) Some(Self(backtrace::Backtrace::new()))
} }
} }
@ -1201,8 +1197,8 @@ struct Backtrace;
#[cfg(not(feature = "debug"))] #[cfg(not(feature = "debug"))]
impl Backtrace { impl Backtrace {
fn new() -> Self { fn new() -> Option<Self> {
Self None
} }
} }