Install a panic handler that prints stuff to the logs, otherwise it only shows up in the console.
()
| 74 | |
| 75 | /// Install a panic handler that prints stuff to the logs, otherwise it only shows up in the console. |
| 76 | fn init_panic_handler() { |
| 77 | let default_hook = std::panic::take_hook(); |
| 78 | |
| 79 | std::panic::set_hook(Box::new(move |info| { |
| 80 | // Do the default first, just in case logging fails too. |
| 81 | default_hook(info); |
| 82 | |
| 83 | // let stacktrace = std::backtrace::Backtrace::capture(); |
| 84 | let stacktrace = std::backtrace::Backtrace::force_capture(); |
| 85 | |
| 86 | tracing::error!( |
| 87 | stacktrace = stacktrace.to_string(), |
| 88 | info = info.to_string(), |
| 89 | "panicking" |
| 90 | ); |
| 91 | |
| 92 | // We could exit the application if any of the background tokio tasks panic. |
| 93 | // However, they are not necessarily critical processes, the chain might still make progress. |
| 94 | // std::process::abort(); |
| 95 | })) |
| 96 | } |
| 97 | |
| 98 | #[tokio::main] |
| 99 | async fn main() { |