diff --git a/src/main.rs b/src/main.rs
index 2f6ae65..bb520a8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,7 +13,7 @@ use std::path::Path;
use std::rc::Rc;
use std::sync::LazyLock;
use thiserror::Error;
-use tracing::{debug, info};
+use tracing::{debug, error, info};
#[derive(Parser)]
#[command(name = "frork")]
@@ -353,13 +353,26 @@ impl LuaAssertion {
impl std::fmt::Display for LuaAssertion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let default_display = || {
+ let args_str = self
+ .args
+ .iter()
+ .map(|v| v.to_string().unwrap_or_else(|_| "?".to_string()))
+ .collect::<Vec<_>>()
+ .join(" ");
+ format!("{} {}", self.name, args_str)
+ };
+
if let Some(ref display_fn) = self.display_fn {
let result = display_fn
.call::<String>(self.args.clone())
- .unwrap_or_else(|_| self.default_display());
+ .unwrap_or_else(|err| {
+ error!("Display function failed for {}: {}", self.name, err);
+ default_display()
+ });
write!(f, "{}", result)
} else {
- write!(f, "{}", self.default_display())
+ write!(f, "{}", default_display())
}
}
}
@@ -386,18 +399,6 @@ impl AssertionType for LuaAssertion {
}
}
-impl LuaAssertion {
- fn default_display(&self) -> String {
- let args_str = self
- .args
- .iter()
- .map(|v| v.to_string().unwrap_or_else(|_| "?".to_string()))
- .collect::<Vec<_>>()
- .join(" ");
- format!("{} {}", self.name, args_str)
- }
-}
-
struct Frork<F> {
// RefCell needed for interior mutability - register() method needs to add
// new assertion types at runtime when called from Lua/Fennel code