Skip to content

Commit

Permalink
chore: use tracing-panic to better capture panic info
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Jul 20, 2024
1 parent 3c81d4c commit 4616f17
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nyanpasu_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ tracing-subscriber = { workspace = true, features = [
"parking_lot",
] }
tracing-attributes.workspace = true
tracing-panic = "0.1"
service-manager = { git = "https://github.com/greenhat616/service-manager-rs.git" }
parking_lot = "0.12"
constcat = "0.5.0"
Expand Down
13 changes: 2 additions & 11 deletions nyanpasu_service/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Context;
use service_manager::ServiceManager;
use tracing_panic::panic_hook;

pub mod dirs;
pub mod os;
Expand Down Expand Up @@ -56,15 +57,5 @@ pub fn deadlock_detection() {

/// Register a panic hook to log the panic message and location, then exit the process.
pub fn register_panic_hook() {
std::panic::set_hook(Box::new(|panic_info| {
let location = panic_info.location().unwrap();
let message = panic_info.payload().downcast_ref::<&str>().unwrap();
tracing::error!(
"panic occurred at {}:{}: {}",
location.file(),
location.line(),
message
);
std::process::exit(1);
}));
std::panic::set_hook(Box::new(panic_hook));
}

0 comments on commit 4616f17

Please sign in to comment.