Print/save panic message
abonander opened this issue · 0 comments
abonander commented
It can be difficult to sort out the exact cause of an explicit panic or assert if its message isn't printed, because the exact source line isn't given in the stack trace;
#13 0x7f8810c2fca9 in std::panicking::begin_panic::h29cf9d60248c6dfc /checkout/src/libstd/panicking.rs:411:4
#14 0x7f8810c458f1 in _$LT$mvp_tree..node..Node$LT$T$GT$$GT$::add_child::h3fdba3b9cf987f7a /home/austin/mvp-tree-rs/fuzz/<panic macros>:3
(^^ panic occurred due to a failed `assert!()` at this frame ^^)
#15 0x7f8810c6273a in _$LT$mvp_tree..MvpTree$LT$T$C$$u20$Df$GT$$GT$::insert::find_insert::hef1424b577421142 /home/austin/mvp-tree-rs/src/lib.rs:65:29
The exact line of a panic is included in the message, which makes it pertinent to save it for presentation to the user. This should be done in the panic hook this lib sets, before it aborts the process.
An easy solution would be to invoke the default panic hook first before aborting:
// clear any custom hook
let _ = panic::take_hook():
// get the default hook
let default_hook = panic::take_hook();
panic::set_hook(move |payload| {
default_hook(payload);
std::process::abort();
});