From 147c8de4100b849d461adebeca9cdbe99b46209e Mon Sep 17 00:00:00 2001 From: "ask-bonk[bot]" Date: Fri, 26 Jun 2026 15:32:08 +0000 Subject: [PATCH] Fix double-panic in panic hook stderr Co-authored-by: fisherdarling --- foundations/src/panic/hook.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/foundations/src/panic/hook.rs b/foundations/src/panic/hook.rs index a98c5d1..94726ea 100644 --- a/foundations/src/panic/hook.rs +++ b/foundations/src/panic/hook.rs @@ -1,5 +1,6 @@ //! Panic hook implementation for tracking panics. +use std::io::Write; use std::panic::{self, PanicHookInfo}; /// Install the panic hook. @@ -57,7 +58,10 @@ fn log_panic(panic_info: &PanicHookInfo<'_>) { "payload": payload, "location": location_str }); - eprintln!("{}", json_output); + // Grab stderr ourselves and ignore any write error to avoid double-panicking + // (e.g. if stderr is closed) within the panic hook. + let mut stderr = std::io::stderr().lock(); + let _ = writeln!(stderr, "{}", json_output); } fn panic_payload_as_str<'a>(panic_info: &'a PanicHookInfo<'_>) -> &'a str {