Add back PanicInfo to backtrace.

This commit is contained in:
Thomas Frans
2022-12-07 11:39:55 +01:00
committed by Henrik Friedrichsen
parent 0a6dd20d54
commit 8a41815bb2

View File

@@ -93,12 +93,11 @@ fn credentials_prompt(error_message: Option<String>) -> Result<Credentials, Stri
authentication::create_credentials()
}
#[inline]
fn register_backtrace_panic_handler() {
// During most of the program, Cursive is responsible for drawing to the
// tty. Since stdout probably doesn't work as expected during a panic, the
// backtrace is written to a file at $USER_CACHE_DIR/ncspot/backtrace.log.
std::panic::set_hook(Box::new(|_panic_info| {
std::panic::set_hook(Box::new(|panic_info| {
// A panic hook will prevent the default panic handler from being
// called. An unwrap in this part would cause a hard crash of ncspot.
// Don't unwrap/expect/panic in here!
@@ -107,6 +106,7 @@ fn register_backtrace_panic_handler() {
path.push("backtrace.log");
if let Ok(mut file) = File::create(path) {
writeln!(file, "{}", backtrace::Backtrace::force_capture()).unwrap_or_default();
writeln!(file, "{}", panic_info).unwrap_or_default();
}
}
}));