From 52bcd3c17b353014cda494f3386b3a04b86ad38e Mon Sep 17 00:00:00 2001 From: Michael Pfaff Date: Sat, 1 Jul 2023 11:41:39 -0400 Subject: [PATCH] Fixed some formatting bugs --- src/context.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/context.rs b/src/context.rs index c02cc4a..d79641a 100644 --- a/src/context.rs +++ b/src/context.rs @@ -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) },