1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#![forbid(unsafe_code)]
use backtrace::Backtrace;
use diem_logger::prelude::*;
use serde::Serialize;
use std::{
panic::{self, PanicInfo},
process,
};
#[derive(Debug, Serialize)]
pub struct CrashInfo {
details: String,
backtrace: String,
}
pub fn setup_panic_handler() {
panic::set_hook(Box::new(move |pi: &PanicInfo<'_>| {
handle_panic(pi);
}));
}
fn handle_panic(panic_info: &PanicInfo<'_>) {
let details = format!("{}", panic_info);
let backtrace = format!("{:#?}", Backtrace::new());
let info = CrashInfo { details, backtrace };
error!(
"{crash_info}",
crash_info = toml::to_string_pretty(&info).unwrap()
);
diem_logger::flush();
process::exit(12);
}