Skip to content

Commit e3fcec8

Browse files
authored
Merge pull request #172 from pragma-org/jeluard/panic-handler
feat: add backtrace to panic_handler
2 parents 73622d5 + 8e2e8a2 commit e3fcec8

1 file changed

Lines changed: 4 additions & 27 deletions

File tree

crates/amaru/src/bin/amaru/panic.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,8 @@
1515
/// Installs a panic handler that prints some useful diagnostics and
1616
/// asks the user to report the issue.
1717
pub fn panic_handler() {
18+
let prev = std::panic::take_hook();
1819
std::panic::set_hook(Box::new(move |info| {
19-
let message = info
20-
.payload()
21-
.downcast_ref::<&str>()
22-
.map(|s| (*s).to_string())
23-
.or_else(|| {
24-
info.payload()
25-
.downcast_ref::<String>()
26-
.map(|s| s.to_string())
27-
})
28-
.unwrap_or_else(|| "unknown error".to_string());
29-
30-
let location = info.location().map_or_else(
31-
|| "".into(),
32-
|location| {
33-
format!(
34-
"{}:{}:{}\n\n ",
35-
location.file(),
36-
location.line(),
37-
location.column(),
38-
)
39-
},
40-
);
41-
4220
// We present the user with a helpful and welcoming error message;
4321
// Block producing nodes should be considered mission critical software, and so
4422
// They should endeavor *never* to crash, and should always handle and recover from errors.
@@ -56,14 +34,13 @@ pub fn panic_handler() {
5634
In your bug report please provide the information below and if possible the code
5735
that produced it.
5836
{info}
59-
60-
{location}{message}"#,
37+
38+
"#,
6139
info = node_info(),
6240
fatal = "amaru::fatal::error",
63-
location = location,
6441
};
65-
6642
eprintln!("\n{}", indent(&error_message, 3));
43+
prev(info);
6744
}));
6845
}
6946

0 commit comments

Comments
 (0)