diff --git a/examples/counter/Cargo.toml b/examples/counter/Cargo.toml index 0861bcfec..12c2f33c2 100644 --- a/examples/counter/Cargo.toml +++ b/examples/counter/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] leptos = { path = "../../leptos" } +console_error_panic_hook = "0.1" console_log = "0.2" log = "0.4" console_error_panic_hook = "0.1.7" diff --git a/examples/counter/src/main.rs b/examples/counter/src/main.rs index 7862bae5e..7180bba63 100644 --- a/examples/counter/src/main.rs +++ b/examples/counter/src/main.rs @@ -2,7 +2,7 @@ use counter::simple_counter; use leptos::*; pub fn main() { + _ = console_log::init_with_level(log::Level::Debug); console_error_panic_hook::set_once(); - // _ = console_log::init_with_level(log::Level::Debug); mount_to_body(simple_counter) } diff --git a/examples/counters-stable/Cargo.toml b/examples/counters-stable/Cargo.toml index 2c69b08fe..81f31d954 100644 --- a/examples/counters-stable/Cargo.toml +++ b/examples/counters-stable/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] leptos = { path = "../../leptos", features = ["stable"] } +console_error_panic_hook = "0.1" log = "0.4" console_log = "0.2" console_error_panic_hook = "0.1.7" diff --git a/examples/counters-stable/src/main.rs b/examples/counters-stable/src/main.rs index 75d98e66e..04126c772 100644 --- a/examples/counters-stable/src/main.rs +++ b/examples/counters-stable/src/main.rs @@ -3,6 +3,7 @@ use leptos::*; fn main() { console_error_panic_hook::set_once(); _ = console_log::init_with_level(log::Level::Debug); + console_error_panic_hook::set_once(); mount_to_body(|cx| view! { cx, }) } diff --git a/examples/counters/Cargo.toml b/examples/counters/Cargo.toml index ee5bc0270..6f3aa302b 100644 --- a/examples/counters/Cargo.toml +++ b/examples/counters/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] leptos = { path = "../../leptos" } +console_error_panic_hook = "0.1" log = "0.4" console_log = "0.2" console_error_panic_hook = "0.1.7" diff --git a/examples/counters/src/main.rs b/examples/counters/src/main.rs index 8d2d1bc7d..428113de8 100644 --- a/examples/counters/src/main.rs +++ b/examples/counters/src/main.rs @@ -4,5 +4,6 @@ use leptos::*; fn main() { console_error_panic_hook::set_once(); _ = console_log::init_with_level(log::Level::Debug); + console_error_panic_hook::set_once(); mount_to_body(|cx| view! { cx, }) } diff --git a/examples/fetch/Cargo.toml b/examples/fetch/Cargo.toml index 16d054347..52f86efe9 100644 --- a/examples/fetch/Cargo.toml +++ b/examples/fetch/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] anyhow = "1.0.58" +console_error_panic_hook = "0.1" leptos = { path = "../../leptos" } reqwasm = "0.5.0" serde = { version = "1", features = ["derive"] } diff --git a/examples/fetch/src/main.rs b/examples/fetch/src/main.rs index 600b0cd58..f8e58eb21 100644 --- a/examples/fetch/src/main.rs +++ b/examples/fetch/src/main.rs @@ -4,6 +4,6 @@ use leptos::*; pub fn main() { console_error_panic_hook::set_once(); _ = console_log::init_with_level(log::Level::Debug); - + console_error_panic_hook::set_once(); mount_to_body(fetch_example) } diff --git a/examples/hackernews/hackernews-app/Cargo.toml b/examples/hackernews/hackernews-app/Cargo.toml index fa9d3bceb..24a76cf63 100644 --- a/examples/hackernews/hackernews-app/Cargo.toml +++ b/examples/hackernews/hackernews-app/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] anyhow = "1" +console_error_panic_hook = "0.1" console_log = "0.2" leptos = { path = "../../../leptos", default-features = false } leptos_meta = { path = "../../../meta", default-features = false } diff --git a/examples/hackernews/hackernews-app/src/main.rs b/examples/hackernews/hackernews-app/src/main.rs index 0559f3ab8..e629873a4 100644 --- a/examples/hackernews/hackernews-app/src/main.rs +++ b/examples/hackernews/hackernews-app/src/main.rs @@ -4,6 +4,7 @@ use leptos::*; pub fn main() { console_error_panic_hook::set_once(); _ = console_log::init_with_level(log::Level::Debug); + console_error_panic_hook::set_once(); mount_to_body(|cx| { view! { cx, } }); diff --git a/examples/hackernews/hackernews-client/Cargo.toml b/examples/hackernews/hackernews-client/Cargo.toml index 525093923..59614ec2b 100644 --- a/examples/hackernews/hackernews-client/Cargo.toml +++ b/examples/hackernews/hackernews-client/Cargo.toml @@ -8,6 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] console_log = "0.2" +console_error_panic_hook = "0.1" hackernews-app = { path = "../hackernews-app", default-features = false, features = ["hydrate"] } leptos = { path = "../../../leptos", default-features = false, features = ["hydrate"] } log = "0.4" \ No newline at end of file diff --git a/examples/hackernews/hackernews-client/src/lib.rs b/examples/hackernews/hackernews-client/src/lib.rs index fcbb633d1..b6a7ef9d6 100644 --- a/examples/hackernews/hackernews-client/src/lib.rs +++ b/examples/hackernews/hackernews-client/src/lib.rs @@ -5,6 +5,7 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen] pub fn main() { _ = console_log::init_with_level(log::Level::Debug); + console_error_panic_hook::set_once(); leptos::hydrate(body().unwrap(), move |cx| { view! { cx, } }); diff --git a/examples/parent-child/Cargo.toml b/examples/parent-child/Cargo.toml index 59e7d0c91..f8bd2c0a3 100644 --- a/examples/parent-child/Cargo.toml +++ b/examples/parent-child/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] leptos = { path = "../../leptos" } +console_error_panic_hook = "0.1" console_log = "0.2" log = "0.4" console_error_panic_hook = "0.1.7" diff --git a/examples/parent-child/src/main.rs b/examples/parent-child/src/main.rs index 063df08e5..ad5602b52 100644 --- a/examples/parent-child/src/main.rs +++ b/examples/parent-child/src/main.rs @@ -2,7 +2,7 @@ use leptos::*; use parent_child::*; pub fn main() { + _ = console_log::init_with_level(log::Level::Debug); console_error_panic_hook::set_once(); - // _ = console_log::init_with_level(log::Level::Debug); mount_to_body(|cx| view! { cx, }) } diff --git a/examples/router/Cargo.toml b/examples/router/Cargo.toml index 7a12f3c98..718543092 100644 --- a/examples/router/Cargo.toml +++ b/examples/router/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] console_log = "0.2" +console_error_panic_hook = "0.1" log = "0.4" leptos = { path = "../../leptos" } leptos_router = { path = "../../router" } diff --git a/examples/router/src/main.rs b/examples/router/src/main.rs index a97da8f73..e54ceff4e 100644 --- a/examples/router/src/main.rs +++ b/examples/router/src/main.rs @@ -4,5 +4,6 @@ use router::router_example; pub fn main() { console_error_panic_hook::set_once(); _ = console_log::init_with_level(log::Level::Debug); + console_error_panic_hook::set_once(); mount_to_body(router_example) } diff --git a/examples/todomvc-ssr/todomvc-ssr-client/Cargo.toml b/examples/todomvc-ssr/todomvc-ssr-client/Cargo.toml index 0a2394a9c..9d09e62c4 100644 --- a/examples/todomvc-ssr/todomvc-ssr-client/Cargo.toml +++ b/examples/todomvc-ssr/todomvc-ssr-client/Cargo.toml @@ -8,6 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] console_log = "0.2" +console_error_panic_hook = "0.1" leptos = { path = "../../../leptos", default-features = false, features = ["hydrate"] } todomvc = { path = "../../todomvc", default-features = false, features = ["hydrate"] } log = "0.4" diff --git a/examples/todomvc-ssr/todomvc-ssr-client/src/lib.rs b/examples/todomvc-ssr/todomvc-ssr-client/src/lib.rs index 18f610d54..8104ba241 100644 --- a/examples/todomvc-ssr/todomvc-ssr-client/src/lib.rs +++ b/examples/todomvc-ssr/todomvc-ssr-client/src/lib.rs @@ -6,6 +6,7 @@ use wasm_bindgen::prelude::wasm_bindgen; pub fn main() { console_error_panic_hook::set_once(); _ = console_log::init_with_level(log::Level::Debug); + console_error_panic_hook::set_once(); log::debug!("initialized logging"); leptos::hydrate(body().unwrap(), |cx| { diff --git a/examples/todomvc/Cargo.toml b/examples/todomvc/Cargo.toml index fe77cae58..a73de9c4d 100644 --- a/examples/todomvc/Cargo.toml +++ b/examples/todomvc/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] leptos = { path = "../../leptos", default-features = false } +console_error_panic_hook = "0.1" miniserde = "0.1" log = "0.4" console_log = "0.2" diff --git a/examples/todomvc/src/main.rs b/examples/todomvc/src/main.rs index 61523b382..84612f4a1 100644 --- a/examples/todomvc/src/main.rs +++ b/examples/todomvc/src/main.rs @@ -3,5 +3,6 @@ pub use todomvc::*; fn main() { console_error_panic_hook::set_once(); _ = console_log::init_with_level(log::Level::Debug); + console_error_panic_hook::set_once(); mount_to_body(|cx| view! { cx, }) } diff --git a/leptos_reactive/src/memo.rs b/leptos_reactive/src/memo.rs index bf86c530e..6f4588579 100644 --- a/leptos_reactive/src/memo.rs +++ b/leptos_reactive/src/memo.rs @@ -91,7 +91,8 @@ where pub fn with(&self, f: impl Fn(&T) -> U) -> U { // okay to unwrap here, because the value will *always* have initially // been set by the effect, synchronously - self.0.with(|n| f(n.as_ref().unwrap())) + self.0 + .with(|n| f(n.as_ref().expect("Memo is missing its initial value"))) } } diff --git a/leptos_reactive/src/resource.rs b/leptos_reactive/src/resource.rs index 14be6362d..2ee1bda4a 100644 --- a/leptos_reactive/src/resource.rs +++ b/leptos_reactive/src/resource.rs @@ -147,9 +147,8 @@ where if let Some(data) = context.resolved_resources.remove(&id) { context.pending_resources.remove(&id); // no longer pending r.resolved.set(true); - //let decoded = base64::decode(&data).unwrap_throw(); - //let res = bincode::deserialize(&decoded).unwrap_throw(); - let res = serde_json::from_str(&data).unwrap_throw(); + let res = + serde_json::from_str(&data).expect_throw("could not deserialize Resource JSON"); r.set_value.update(|n| *n = Some(res)); r.set_loading.update(|n| *n = false); @@ -163,9 +162,8 @@ where let set_value = r.set_value; let set_loading = r.set_loading; move |res: String| { - //let decoded = base64::decode(&res).unwrap_throw(); - //let res = bincode::deserialize(&decoded).unwrap_throw(); - let res = serde_json::from_str(&res).unwrap_throw(); + let res = serde_json::from_str(&res) + .expect_throw("could not deserialize JSON for already-resolved Resource"); resolved.set(true); set_value.update(|n| *n = res); set_loading.update(|n| *n = false); @@ -177,8 +175,8 @@ where &web_sys::window().unwrap(), &wasm_bindgen::JsValue::from_str("__LEPTOS_RESOURCE_RESOLVERS"), ) - .unwrap(); - let id = serde_json::to_string(&id).unwrap(); + .expect_throw("no __LEPTOS_RESOURCE_RESOLVERS found in the JS global scope"); + let id = serde_json::to_string(&id).expect_throw("could not deserialize Resource ID"); _ = js_sys::Reflect::set( &resource_resolvers, &wasm_bindgen::JsValue::from_str(&id), @@ -418,8 +416,10 @@ where let fut = (self.fetcher)(self.source.get()); Box::pin(async move { let res = fut.await; - (id, serde_json::to_string(&res).unwrap()) - //(id, base64::encode(&bincode::serialize(&res).unwrap())) + ( + id, + serde_json::to_string(&res).expect("could not serialize Resource"), + ) }) } } diff --git a/leptos_reactive/src/runtime.rs b/leptos_reactive/src/runtime.rs index 86a452044..91e5cd973 100644 --- a/leptos_reactive/src/runtime.rs +++ b/leptos_reactive/src/runtime.rs @@ -166,7 +166,7 @@ impl Runtime { for i in 0..templates.length() { let node = templates .item(i) - .unwrap_throw() + .unwrap_throw() // ok to unwrap; we already have the index, so this can't fail .unchecked_into::(); let key = node.get_attribute("data-hk").unwrap_throw(); registry.insert(key, node); diff --git a/leptos_reactive/src/scope.rs b/leptos_reactive/src/scope.rs index 6cf107736..725bd98b6 100644 --- a/leptos_reactive/src/scope.rs +++ b/leptos_reactive/src/scope.rs @@ -65,7 +65,11 @@ impl Scope { pub fn child_scope(self, f: impl FnOnce(Scope)) -> ScopeDisposer { let (_, child_id, disposer) = self.runtime.run_scope_undisposed(f, Some(self)); let mut children = self.runtime.scope_children.borrow_mut(); - children.entry(self.id).unwrap().or_default().push(child_id); + children + .entry(self.id) + .expect("trying to add a child to a Scope that has already been disposed") + .or_default() + .push(child_id); disposer } @@ -145,7 +149,7 @@ pub fn on_cleanup(cx: Scope, cleanup_fn: impl FnOnce() + 'static) { let mut cleanups = cx.runtime.scope_cleanups.borrow_mut(); let cleanups = cleanups .entry(cx.id) - .unwrap() + .expect("trying to clean up a Scope that has already been disposed") .or_insert_with(Default::default); cleanups.push(Box::new(cleanup_fn)); } @@ -193,10 +197,10 @@ impl Scope { .unchecked_ref::() .content() .clone_node_with_deep(true) - .unwrap_throw() + .expect_throw("(get_next_element) could not clone template") .unchecked_into::() .first_element_child() - .unwrap_throw(); + .expect_throw("(get_next_element) could not get first child of template"); t }; diff --git a/router/src/data/loader.rs b/router/src/data/loader.rs index 6fb91f792..dd0dac3c1 100644 --- a/router/src/data/loader.rs +++ b/router/src/data/loader.rs @@ -44,11 +44,10 @@ where .downcast_ref::() .cloned() .unwrap_or_else(|| { - debug_warn!( + panic!( "use_loader() could not downcast to {:?}", std::any::type_name::(), - ); - panic!() + ) }) } }, @@ -81,7 +80,10 @@ where cx, move || (params.get(), url()), move |(params, url)| async move { - log::debug!("[LOADER] calling loader; should fire whenever params or URL change"); + log::debug!( + "[LOADER] calling loader with {:#?}; should fire whenever params or URL change", + (params, url) + ); let route = use_route(cx); let query = use_query_map(cx);