Fixed some formatting bugs

This commit is contained in:
Michael Pfaff 2023-07-01 11:41:39 -04:00
parent 8f1c7d9765
commit 52bcd3c17b
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
1 changed files with 10 additions and 5 deletions

View File

@ -5,6 +5,9 @@ use std::fmt;
use std::panic::Location;
use std::sync::Arc;
use crate::ReportOpts;
use crate::report::report_write;
/// Provides context furthering the explanation of *how* you got to an error.
#[derive(Debug)]
#[cfg_attr(feature = "clone-with-caveats", derive(Clone))]
@ -23,8 +26,10 @@ impl fmt::Display for Context {
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.detail.fmt(f)?;
let opts = ReportOpts::default();
for detail in &self.extra {
write!(f, "\n- {detail}")?;
f.write_str("\n")?;
report_write!(f, &opts.indent().next(), "- {detail}")?;
}
Ok(())
}
@ -64,15 +69,15 @@ impl fmt::Display for Detail {
Self::String(s) => f.write_str(s),
Self::Location(l) => write!(f, "At {l}"),
#[cfg(feature = "backtrace")]
Self::Backtrace(Backtrace::Unsupported) => f.write_str("\nI'd like to show you a backtrace,\n but it's not supported on your platform"),
Self::Backtrace(Backtrace::Unsupported) => f.write_str("I'd like to show you a backtrace,\n but it's not supported on your platform"),
#[cfg(feature = "backtrace")]
Self::Backtrace(Backtrace::Disabled) => f.write_str("\nIf you'd like a backtrace,\n try again with RUST_BACKTRACE=1"),
Self::Backtrace(Backtrace::Disabled) => f.write_str("If you'd like a backtrace,\n try again with RUST_BACKTRACE=1"),
#[cfg(feature = "backtrace")]
Self::Backtrace(Backtrace::Other(status, bt)) => {
f.write_str(if *status == BacktraceStatus::Captured {
"\nHere is the backtrace:\n"
"Here is the backtrace:\n"
} else {
"\nI can't tell if backtraces are working,\n but I'll give it a go:\n"
"I can't tell if backtraces are working,\n but I'll give it a go:\n"
})?;
write!(f, "{}", bt)
},