Skip to content

Commit

Permalink
refine error logs; tag 0.1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jul 30, 2024
1 parent 402fef7 commit bf8c7bd
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion respo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "respo"
version = "0.1.10"
version = "0.1.11"
edition = "2021"
description = "a tiny virtual DOM library migrated from ClojureScript"
license = "Apache-2.0"
Expand Down
6 changes: 4 additions & 2 deletions respo/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ pub trait RespoApp {
DispatchFn::new(dispatch_action),
Self::get_loop_delay(),
)
.expect("rendering node");
.unwrap_or_else(|e| {
util::error_log!("render loop error: {:?}", e);
});

Ok(())
}
Expand Down Expand Up @@ -123,7 +125,7 @@ pub trait RespoApp {
*store.borrow_mut() = s;
}
Err(e) => {
util::log!("error: {:?}", e);
util::error_log!("error: {:?}", e);
}
},
_ => {
Expand Down
6 changes: 3 additions & 3 deletions respo/src/app/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where
}
}
} else {
crate::util::log!("expected component for effects, got: {}", target_tree);
crate::util::warn_log!("expected component for effects, got: {}", target_tree);
}
}
}
Expand Down Expand Up @@ -243,7 +243,7 @@ where
}
}
} else {
crate::util::log!("expected component for effects, got: {}", target_tree);
crate::util::warn_log!("expected component for effects, got: {}", target_tree);
}
}
}
Expand Down Expand Up @@ -272,7 +272,7 @@ where
}
}
} else {
crate::util::log!("expected component for effects, got: {}", target_tree);
crate::util::warn_log!("expected component for effects, got: {}", target_tree);
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions respo/src/app/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ fn drain_rerender_status() -> bool {
let ret = { *NEED_TO_ERENDER.read().expect("to drain rerender status") };

if ret {
let mut need_to_erender = NEED_TO_ERENDER.write().expect("to drain rerender status");
*need_to_erender = false;
let mut need_to_rerender = NEED_TO_ERENDER.write().expect("to drain rerender status");
*need_to_rerender = false;
}
ret
}
Expand Down Expand Up @@ -108,17 +108,15 @@ where
let mut changes: Vec<DomChange<T>> = vec![];
diff_tree(&new_tree, &to_prev_tree.borrow(), &Vec::new(), &Vec::new(), &mut changes)?;

// use cirru_parser::CirruWriterOptions;
// util::log!(
// "prev tree: {}",
// cirru_parser::format(
// &[to_prev_tree2.borrow().to_owned().into()],
// cirru_parser::CirruWriterOptions { use_inline: true }
// )
// .unwrap()
// cirru_parser::format(&[to_prev_tree.borrow().to_owned().into()], CirruWriterOptions { use_inline: true }).unwrap()
// );
// use crate::dom_change::changes_to_cirru;
// util::log!(
// "changes: {}",
// cirru_parser::format(&[changes_to_cirru(&changes)], cirru_parser::CirruWriterOptions { use_inline: true }).unwrap()
// cirru_parser::format(&[changes_to_cirru(&changes)], CirruWriterOptions { use_inline: true }).unwrap()
// );

let handler = handle_event.to_owned();
Expand Down
21 changes: 19 additions & 2 deletions respo/src/app/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ pub fn raf_loop_slow(interval: i32, mut cb: Box<dyn FnMut() -> Result<(), String

*g.borrow_mut() = Some(Closure::wrap(Box::new(move || {
if let Err(e) = cb() {
crate::log!("failed in slow loop: {}", e);
crate::warn_log!(
"Failure in slow loop, program has to stop since inconsistent states. Details: {}",
e
);
}

let h = Closure::wrap(Box::new({
Expand Down Expand Up @@ -95,7 +98,7 @@ macro_rules! log {
///
/// use it like:
/// ```ignore
/// util::warn!("a is {}", a);
/// util::warn_log!("a is {}", a);
/// ```
#[macro_export]
macro_rules! warn_log {
Expand All @@ -104,6 +107,20 @@ macro_rules! warn_log {
}};
}

/// wraps on top of `web_sys::console.error_1`.
///
/// use it like:
/// ```ignore
/// util::error_log!("a is {}", a);
/// ```
#[macro_export]
macro_rules! error_log {
($($t:tt)*) => {{
web_sys::console::error_1(&format!($($t)*).into());
}};
}

pub use error_log;
pub use log;
pub use warn_log;

Expand Down
4 changes: 2 additions & 2 deletions respo/src/ui/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl RespoEffect for EffectModalFade {
delay_call.forget();
}
None => {
util::log!("content not found");
util::warn_log!("content not found");
}
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ impl RespoEffect for EffectDrawerFade {
delay_call.forget();
}
None => {
app::util::log!("content not found");
app::util::warn_log!("content not found");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion respo/src/ui/dialog/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ where
let window = web_sys::window().unwrap();
// dirty global variable to store a shared callback
if let Err(e) = Reflect::set(&window, &JsValue::from_str(NEXT_TASK_NAME), task.as_ref()) {
app::util::log!("failed to store next task {:?}", e);
app::util::error_log!("failed to store next task {:?}", e);
}
task.forget();
dispatch.run_state(&self.cursor, s)?;
Expand Down
2 changes: 1 addition & 1 deletion respo/src/ui/dialog/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ where
let window = web_sys::window().unwrap();
// dirty global variable to store a shared callback
if let Err(e) = Reflect::set(&window, &JsValue::from_str(NEXT_TASK_NAME), task.as_ref()) {
util::log!("failed to store next task {:?}", e);
util::error_log!("failed to store next task {:?}", e);
}
task.forget();
dispatch.run_state(&self.cursor, s)?;
Expand Down

0 comments on commit bf8c7bd

Please sign in to comment.