mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
Improve error messages by moving unwrap => expect
This commit is contained in:
parent
a463bcca43
commit
0e1f3c567f
5 changed files with 27 additions and 20 deletions
|
@ -91,7 +91,8 @@ where
|
|||
pub fn with<U>(&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")))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<web_sys::Element>();
|
||||
let key = node.get_attribute("data-hk").unwrap_throw();
|
||||
registry.insert(key, node);
|
||||
|
|
|
@ -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::<web_sys::HtmlTemplateElement>()
|
||||
.content()
|
||||
.clone_node_with_deep(true)
|
||||
.unwrap_throw()
|
||||
.expect_throw("(get_next_element) could not clone template")
|
||||
.unchecked_into::<web_sys::Element>()
|
||||
.first_element_child()
|
||||
.unwrap_throw();
|
||||
.expect_throw("(get_next_element) could not get first child of template");
|
||||
t
|
||||
};
|
||||
|
||||
|
|
|
@ -44,11 +44,10 @@ where
|
|||
.downcast_ref::<T>()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| {
|
||||
debug_warn!(
|
||||
panic!(
|
||||
"use_loader() could not downcast to {:?}",
|
||||
std::any::type_name::<T>(),
|
||||
);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue