Skip to content

Commit

Permalink
Restore 'Stack backtrace:' above the backtrace
Browse files Browse the repository at this point in the history
The header originally printed by the backtrace crate was removed in
rust-lang/backtrace-rs#286 to give downstream
formatting code a chance to incorporate whatever kind of header they
want. So we do that.
  • Loading branch information
dtolnay committed May 15, 2020
1 parent 2aa0cc1 commit 6d33c15
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}

Expand Down

0 comments on commit 6d33c15

Please sign in to comment.