feat(core): enable enhanced panic diagnostics and observability

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.
This commit is contained in:
Tunglies 2026-04-12 03:06:16 +08:00
parent 0e38ccbb9d
commit 6fea76f7e3
No known key found for this signature in database
GPG Key ID: B9B01B389469B3E8
2 changed files with 20 additions and 3 deletions

View File

@ -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]

View File

@ -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(())
}