From 0eccc4e370cd970dd697e9cceff71d60c26cf1e6 Mon Sep 17 00:00:00 2001 From: John Howard <49204095+Royalflamejlh@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:43:45 -0700 Subject: [PATCH 1/2] xcl run: a panic on any thread is written to xcl.log A panic was printed to stderr only. One of XCL's own threads that panics is gone for the rest of the run, and `xcl.log`, the file a report carries, had no line of it: in a retail title's run under Wine (RTX 4060 Ti) `xcl-sync-watchdog` panicked as it started (the race #1926 fixes) and the log reads like any other stall. The host installs a panic hook that writes the thread's name, the place and the message as an ERROR line, then calls the hook that was there. Co-Authored-By: Claude Fable 5.2 --- crates/xcl/src/host.rs | 1 + crates/xcl/src/log.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/crates/xcl/src/host.rs b/crates/xcl/src/host.rs index f3e57ce5f..87fb75235 100644 --- a/crates/xcl/src/host.rs +++ b/crates/xcl/src/host.rs @@ -21,6 +21,7 @@ pub fn host_main(boot_path: &Path) -> i32 { crate::log::Level::parse(&boot.config.log_level), boot.config.log_to_stderr, ); + crate::log::log_panics(); crate::xlog_info!("XCL {} – host for '{}'", env!("CARGO_PKG_VERSION"), boot.title); crate::xlog_info!("game: {} (read-only folder: {})", boot.exe_path.display(), boot.game_root.display()); crate::xlog_info!("XCL data: {}", boot.data_dir.display()); diff --git a/crates/xcl/src/log.rs b/crates/xcl/src/log.rs index 76b51b788..63cad12f2 100644 --- a/crates/xcl/src/log.rs +++ b/crates/xcl/src/log.rs @@ -97,6 +97,17 @@ pub fn flush() { } } +/// A panic goes to the log as well as to stderr: a thread of XCL's that dies is gone for the +/// run, and the log is what a report carries (a retail title's run lost `xcl-sync-watchdog` so, +/// with nothing in `xcl.log`). +pub fn log_panics() { + let print = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |info| { + write(Level::Error, format_args!("thread '{}' {}", std::thread::current().name().unwrap_or(""), info.to_string().replace('\n', " "))); + print(info); + })); +} + #[macro_export] macro_rules! xlog_error { ($($a:tt)*) => { $crate::log::write($crate::log::Level::Error, format_args!($($a)*)) } } #[macro_export] @@ -107,3 +118,22 @@ macro_rules! xlog_info { ($($a:tt)*) => { $crate::log::write($crate::log::Level: macro_rules! xlog_debug { ($($a:tt)*) => { if $crate::log::enabled($crate::log::Level::Debug) { $crate::log::write($crate::log::Level::Debug, format_args!($($a)*)) } } } #[macro_export] macro_rules! xlog_trace { ($($a:tt)*) => { if $crate::log::enabled($crate::log::Level::Trace) { $crate::log::write($crate::log::Level::Trace, format_args!($($a)*)) } } } + +#[cfg(test)] +mod tests { + use super::*; + + /// A thread that panics leaves its name, the place and the message in the log file. + #[test] + fn a_panic_is_in_the_log() { + let path = std::env::temp_dir().join(format!("xcl-log-panics-{}.log", std::process::id())); + *FILE.lock().unwrap() = Some(File::create(&path).unwrap()); + log_panics(); + let died = std::thread::Builder::new().name("xcl-dies".into()).spawn(|| panic!("gone for the run")).unwrap().join(); + *FILE.lock().unwrap() = None; + let log = std::fs::read_to_string(&path).unwrap(); + let _ = std::fs::remove_file(&path); + assert!(died.is_err()); + assert!(log.contains("thread 'xcl-dies' panicked at ") && log.contains("gone for the run"), "the log: {log:?}"); + } +} From ecda9387592078f32ee5e5d02a917ee86d73d29f Mon Sep 17 00:00:00 2001 From: John Howard <49204095+Royalflamejlh@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:43:42 -0700 Subject: [PATCH 2/2] xcl run: shorter comments on the panic hook Co-Authored-By: Claude Fable 5.2 --- crates/xcl/src/log.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/xcl/src/log.rs b/crates/xcl/src/log.rs index 63cad12f2..7f5d1f180 100644 --- a/crates/xcl/src/log.rs +++ b/crates/xcl/src/log.rs @@ -97,9 +97,7 @@ pub fn flush() { } } -/// A panic goes to the log as well as to stderr: a thread of XCL's that dies is gone for the -/// run, and the log is what a report carries (a retail title's run lost `xcl-sync-watchdog` so, -/// with nothing in `xcl.log`). +/// A panic goes to the log as well as to stderr. pub fn log_panics() { let print = std::panic::take_hook(); std::panic::set_hook(Box::new(move |info| { @@ -123,7 +121,6 @@ macro_rules! xlog_trace { ($($a:tt)*) => { if $crate::log::enabled($crate::log:: mod tests { use super::*; - /// A thread that panics leaves its name, the place and the message in the log file. #[test] fn a_panic_is_in_the_log() { let path = std::env::temp_dir().join(format!("xcl-log-panics-{}.log", std::process::id()));