Skip to content

Commit 16ef572

Browse files
committed
⚡ catch panic as tracing log
1 parent 65f4310 commit 16ef572

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

crates/desktop/src/logging.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,23 @@ pub fn setup()
4949
.with(console_log_layer)
5050
.init();
5151

52+
std::panic::set_hook(Box::new(|panic| {
53+
// If the panic has a source location, record it as structured fields.
54+
if let Some(location) = panic.location() {
55+
// On nightly Rust, where the `PanicInfo` type also exposes a
56+
// `message()` method returning just the message, we could record
57+
// just the message instead of the entire `fmt::Display`
58+
// implementation, avoiding the duplicated location
59+
tracing::error!(
60+
message = %panic,
61+
panic.file = location.file(),
62+
panic.line = location.line(),
63+
panic.column = location.column(),
64+
);
65+
} else {
66+
tracing::error!(message = %panic);
67+
}
68+
}));
69+
5270
Ok((console_guard, file_guard))
5371
}

0 commit comments

Comments
 (0)