Skip to content

Commit

Permalink
use tracing::* through lib code
Browse files Browse the repository at this point in the history
not yet in testing, and for some errors!
  • Loading branch information
WorldSEnder committed Aug 6, 2022
1 parent f56439a commit 00ae994
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/yew-router/Cargo.toml
Expand Up @@ -21,6 +21,7 @@ gloo = { version = "0.8", features = ["futures"] }
route-recognizer = "0.3"
serde = "1"
serde_urlencoded = "0.7.1"
tracing = "0.1.36"

[dependencies.web-sys]
version = "0.3"
Expand Down
3 changes: 1 addition & 2 deletions packages/yew-router/src/switch.rs
@@ -1,6 +1,5 @@
//! The [`Switch`] Component.

use gloo::console;
use yew::prelude::*;

use crate::prelude::*;
Expand Down Expand Up @@ -41,7 +40,7 @@ where
match route {
Some(route) => props.render.emit(route),
None => {
console::warn!("no route matched");
tracing::warn!("no route matched");
Html::default()
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/yew/src/dom_bundle/bnode.rs
Expand Up @@ -2,7 +2,6 @@

use std::fmt;

use gloo::console;
use web_sys::{Element, Node};

use super::{BComp, BList, BPortal, BSubtree, BSuspense, BTag, BText};
Expand Down Expand Up @@ -54,7 +53,7 @@ impl ReconcileTarget for BNode {
Self::Ref(ref node) => {
// Always remove user-defined nodes to clear possible parent references of them
if parent.remove_child(node).is_err() {
console::warn!("Node not found to remove VRef");
tracing::warn!("Node not found to remove VRef");
}
}
Self::Portal(bportal) => bportal.detach(root, parent, parent_to_detach),
Expand Down
3 changes: 1 addition & 2 deletions packages/yew/src/dom_bundle/btag/mod.rs
Expand Up @@ -7,7 +7,6 @@ use std::borrow::Cow;
use std::hint::unreachable_unchecked;
use std::ops::DerefMut;

use gloo::console;
use gloo::utils::document;
use listeners::ListenerRegistration;
pub use listeners::Registry;
Expand Down Expand Up @@ -84,7 +83,7 @@ impl ReconcileTarget for BTag {
let result = parent.remove_child(&node);

if result.is_err() {
console::warn!("Node not found to remove VTag");
tracing::warn!("Node not found to remove VTag");
}
}
// It could be that the ref was already reused when rendering another element.
Expand Down
3 changes: 1 addition & 2 deletions packages/yew/src/dom_bundle/btext.rs
@@ -1,6 +1,5 @@
//! This module contains the bundle implementation of text [BText].

use gloo::console;
use gloo::utils::document;
use web_sys::{Element, Text as TextNode};

Expand All @@ -21,7 +20,7 @@ impl ReconcileTarget for BText {
let result = parent.remove_child(&self.text_node);

if result.is_err() {
console::warn!("Node not found to remove VText");
tracing::warn!("Node not found to remove VText");
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions packages/yew/src/dom_bundle/utils.rs
Expand Up @@ -6,8 +6,18 @@ pub(super) fn insert_node(node: &Node, parent: &Element, next_sibling: Option<&N
Some(next_sibling) => parent
.insert_before(node, Some(next_sibling))
.unwrap_or_else(|err| {
gloo::console::error!("failed to insert node", err, parent, next_sibling, node);
panic!("failed to insert tag before next sibling")
// Log normally, so we can inspect the nodes in console
gloo::console::error!(
"failed to insert node before next sibling",
err,
parent,
next_sibling,
node
);
// Log via tracing for consistency
tracing::error!("failed to insert node before next sibling");
// Panic to short-curcuit and fail
panic!("failed to insert node before next sibling")
}),
None => parent.append_child(node).expect("failed to append child"),
};
Expand Down

0 comments on commit 00ae994

Please sign in to comment.