From 6fea76f7e3bca92129db7dc2c199e3bdf3f21593 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sun, 12 Apr 2026 03:06:16 +0800 Subject: [PATCH] feat(core): enable enhanced panic diagnostics and observability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Transitioned panic strategy from 'abort' to 'unwind' and integrated a global panic hook into the logging framework. This change allows the application to capture critical failure metadata— including specific file locations, line numbers, and panic payloads— persisting them to local logs before exit. Note: We prioritize troubleshooting capability and long-term stability at this stage. Reverting to 'panic = abort', `debug = false`, `strip = true`, `remove split-debuginfo` for peak performance and minimal binary size will only be considered once the project reaches a mature state with near-zero community-reported crashes. --- Cargo.toml | 7 ++++--- src-tauri/src/core/logger.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ffb5aa371..d1bbcbba0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,14 @@ members = [ resolver = "2" [profile.release] -panic = "abort" +panic = "unwind" codegen-units = 1 lto = "thin" opt-level = 3 -debug = false -strip = true +debug = 1 +strip = "none" overflow-checks = false +split-debuginfo = "unpacked" rpath = false [profile.dev] diff --git a/src-tauri/src/core/logger.rs b/src-tauri/src/core/logger.rs index 81ffeffd9..be619b65e 100644 --- a/src-tauri/src/core/logger.rs +++ b/src-tauri/src/core/logger.rs @@ -100,6 +100,22 @@ impl Logger { let sidecar_file_writer = self.generate_sidecar_writer()?; *self.sidecar_file_writer.write() = Some(sidecar_file_writer); + std::panic::set_hook(Box::new(move |info| { + let payload = info + .payload() + .downcast_ref::<&str>() + .unwrap_or(&"Unknown panic payload"); + let location = info + .location() + .map(|loc| format!("{}:{}", loc.file(), loc.line())) + .unwrap_or_else(|| "Unknown location".to_string()); + logging!(error, Type::System, "Panic occurred at {}: {}", location, payload); + if let Some(h) = Self::global().handle.lock().as_ref() { + h.flush(); + std::thread::sleep(std::time::Duration::from_millis(100)); + } + })); + Ok(()) }