From 8bae558140b737c4fff09db3811ca2a4680433e3 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Wed, 26 Jan 2022 20:17:06 -0500 Subject: [PATCH] Better debugging in the browser console --- Cargo.lock | 11 +++++++++++ web/Cargo.toml | 2 ++ web/src/main.rs | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 5a8ac09..86b647d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -318,6 +318,16 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "cpufeatures" version = "0.2.1" @@ -1751,6 +1761,7 @@ checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" name = "web" version = "0.1.0" dependencies = [ + "console_error_panic_hook", "recipes", "reqwasm", "sycamore", diff --git a/web/Cargo.toml b/web/Cargo.toml index 22ef2fe..b93ba54 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -8,6 +8,8 @@ edition = "2021" [dependencies] recipes = {path = "../recipes" } reqwasm = "0.4.0" +# This makes debugging panics more tractable. +console_error_panic_hook = "0.1.7" [dependencies.wasm-bindgen] version = "0.2.79" diff --git a/web/src/main.rs b/web/src/main.rs index 7ee778b..a135ec4 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -18,5 +18,9 @@ use sycamore::prelude::*; use web::UI; fn main() { + #[cfg(debug_assertions)] + { + console_error_panic_hook::set_once(); + } sycamore::render(|| view! { UI() }); }