From 0fad328ce60302dce82826127c1e2943dadf1996 Mon Sep 17 00:00:00 2001 From: Daniel Knopik Date: Thu, 9 Oct 2025 11:21:46 +0200 Subject: [PATCH] feat: add panic hook for logging --- anchor/src/main.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/anchor/src/main.rs b/anchor/src/main.rs index b6f5299c7..dc95409e0 100644 --- a/anchor/src/main.rs +++ b/anchor/src/main.rs @@ -1,3 +1,5 @@ +use std::backtrace::Backtrace; + use clap::Parser; use client::{Client, Node, config}; use environment::Environment; @@ -262,5 +264,15 @@ pub fn enable_logging( .try_init() .map_err(|e| format!("Failed to initialize logging: {e}"))?; + std::panic::set_hook(Box::new(move |info| { + error!( + location = info.location().map(ToString::to_string), + message = info.payload().downcast_ref::(), + backtrace = %Backtrace::capture(), + advice = "Please check above for a backtrace and notify the developers", + "TASK PANIC. This is a bug!" + ); + })); + Ok(guards) }