From aeab0b73e5881e473e57c18d57d785cf52c5e974 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Fri, 17 Nov 2023 16:42:40 +0100 Subject: [PATCH] optional backtrace on panic --- libsql-server/src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libsql-server/src/main.rs b/libsql-server/src/main.rs index 0c9a98b662..f95fb3af02 100644 --- a/libsql-server/src/main.rs +++ b/libsql-server/src/main.rs @@ -526,7 +526,15 @@ async fn main() -> Result<()> { ) .init(); - std::panic::set_hook(Box::new(tracing_panic::panic_hook)); + std::panic::set_hook(Box::new(|p| { + tracing_panic::panic_hook(p); + if let Ok(v) = std::env::var("RUST_BACKTRACE") { + if !v.is_empty() { + let bt = std::backtrace::Backtrace::force_capture(); + eprintln!("{bt}"); + } + } + })); let args = Cli::parse();