MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / panic_hook

Function panic_hook

crates/bindings/src/logger.rs:14–33  ·  view source on GitHub ↗

Our own panic hook logging to the console.

(info: &panic::PanicHookInfo)

Source from the content-addressed store, hash-verified

12
13/// Our own panic hook logging to the console.
14fn panic_hook(info: &panic::PanicHookInfo) {
15 // Try to look into some string types we know (`&'static str` and `String`).
16 let msg = match info.payload().downcast_ref::<&'static str>() {
17 Some(s) => *s,
18 None => match info.payload().downcast_ref::<String>() {
19 Some(s) => &s[..],
20 None => "Box<dyn Any>",
21 },
22 };
23
24 // Log the panic message to the console.
25 let location = info.location();
26 sys::console_log(
27 sys::LogLevel::Panic,
28 None,
29 location.map(|l| l.file()),
30 location.map(|l| l.line()),
31 msg,
32 )
33}
34
35struct Logger {
36 // `Mutex` is fine here because WASM is single-threaded;

Callers

nothing calls this directly

Calls 2

console_logFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…