Our own panic hook logging to the console.
(info: &panic::PanicHookInfo)
| 12 | |
| 13 | /// Our own panic hook logging to the console. |
| 14 | fn 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 | |
| 35 | struct Logger { |
| 36 | // `Mutex` is fine here because WASM is single-threaded; |
nothing calls this directly
no test coverage detected
searching dependent graphs…