1
1
mirror of https://github.com/wez/wezterm.git synced 2025-01-08 23:17:36 +03:00

capture panic backtrace to log file

This commit is contained in:
Wez Furlong 2022-04-27 14:47:28 -07:00
parent 97005b8c1c
commit efcc4b48c1
3 changed files with 25 additions and 0 deletions

1
Cargo.lock generated
View File

@ -1090,6 +1090,7 @@ dependencies = [
name = "env-bootstrap"
version = "0.1.0"
dependencies = [
"backtrace",
"chrono",
"cocoa",
"config",

View File

@ -7,6 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
backtrace = "0.3"
chrono = {version="0.4", features=["unstable-locales"]}
config = { path = "../config" }
dirs-next = "2.0"

View File

@ -136,8 +136,31 @@ pub fn set_lang_from_locale() {
}
}
fn register_panic_hook() {
let default_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
let payload = info.payload();
let payload = payload.downcast_ref::<&str>().unwrap_or(&"!?");
let bt = backtrace::Backtrace::new();
if let Some(loc) = info.location() {
log::error!(
"panic at {}:{}:{} - {}\n{:?}",
loc.file(),
loc.line(),
loc.column(),
payload,
bt
);
} else {
log::error!("panic - {}\n{:?}", payload, bt);
}
default_hook(info);
}));
}
pub fn bootstrap() {
setup_logger();
register_panic_hook();
set_wezterm_executable();