Move empty-source check from eval_raw to load_string
eval_raw shouldn't reject empty source — the caller may want side
effects from setup with no source to evaluate. The empty check belongs
in load_string, where nil/empty is almost certainly a mistake in a
config file.
diff --git a/src/fennel.rs b/src/fennel.rs
index 02a6cb3..0466b4b 100644
--- a/src/fennel.rs
+++ b/src/fennel.rs
@@ -92,12 +92,6 @@ impl Fennel {
name: &str,
setup: impl Fn(&Lua) -> mlua::Result<()>,
) -> Result<mlua::Value, FennelError> {
- if source.trim().is_empty() {
- return Err(FennelError::Empty {
- name: name.to_string(),
- });
- }
-
setup(&self.lua).map_err(|e| FennelError::from_lua(source, name, e))?;
let fennel: mlua::Table = self.lua.globals().get("fennel")?;
@@ -124,6 +118,12 @@ impl Fennel {
where
T: serde::de::DeserializeOwned,
{
+ if source.trim().is_empty() {
+ return Err(FennelError::Empty {
+ name: name.to_string(),
+ });
+ }
+
let result = self.eval_raw(source, name, |_| Ok(()))?;
// Reject nil results — a config file that evaluates to nothing is