From 6d33c15b96c1d162ee820fb0d35ca34e71dccc5b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 14 May 2020 21:48:04 -0700 Subject: [PATCH] Restore 'Stack backtrace:' above the backtrace The header originally printed by the backtrace crate was removed in https://github.com/rust-lang/backtrace-rs/pull/286 to give downstream formatting code a chance to incorporate whatever kind of header they want. So we do that. --- src/fmt.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fmt.rs b/src/fmt.rs index 16a82ba..be93e1a 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -45,12 +45,17 @@ impl ErrorImpl<()> { let backtrace = self.backtrace(); if let BacktraceStatus::Captured = backtrace.status() { let mut backtrace = backtrace.to_string(); + write!(f, "\n\n")?; if backtrace.starts_with("stack backtrace:") { // Capitalize to match "Caused by:" backtrace.replace_range(0..1, "S"); + } else { + // "stack backtrace:" prefix was removed in + // https://github.com/rust-lang/backtrace-rs/pull/286 + writeln!(f, "Stack backtrace:")?; } backtrace.truncate(backtrace.trim_end().len()); - write!(f, "\n\n{}", backtrace)?; + write!(f, "{}", backtrace)?; } }