Skip to main content

saola_user_facing_errors/
panic_hook.rs

1pub fn set_panic_hook() {
2    let original_hook = std::panic::take_hook();
3
4    std::panic::set_hook(Box::new(move |panic| {
5        let err = crate::Error::new_in_panic_hook(panic);
6
7        match serde_json::to_writer(std::io::stderr(), &err) {
8            Ok(_) => eprintln!(),
9            Err(err) => {
10                tracing::error!("Failed to write JSON error to stderr: {}", err);
11                original_hook(panic)
12            }
13        }
14
15        std::process::exit(255)
16    }));
17}