From 3ce774a2a050d5ee466d1c8f20bf05d6917a6ef6 Mon Sep 17 00:00:00 2001 From: Brent Pedersen Date: Tue, 18 Feb 2025 17:44:05 -0800 Subject: [PATCH] add more informative error closes #2 --- src/vcfexpress.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/vcfexpress.rs b/src/vcfexpress.rs index 5f02813..1a8a1af 100644 --- a/src/vcfexpress.rs +++ b/src/vcfexpress.rs @@ -173,7 +173,9 @@ impl<'lua> VCFExpress<'lua> { lua.scope(|scope| { globals.raw_set("header", scope.create_any_userdata_ref_mut(&mut hv)?)?; for path in lua_prelude { - let code = std::fs::read_to_string(&path)?; + let code = std::fs::read_to_string(&path).map_err(|e| { + mlua::Error::RuntimeError(format!("Error reading file {}: {}", path, e)) + })?; lua.load(&code).set_name(path).exec()?; } Ok(()) @@ -255,7 +257,8 @@ impl<'lua> VCFExpress<'lua> { /// Add lua code to the Lua interpreter. This code will be available to the expressions and the template. /// These are not the variant expressions, but rather additional Lua code that can be used as a library. pub fn add_lua_code(&mut self, path: &str) -> Result<(), Box> { - let code = std::fs::read_to_string(path)?; + let code = std::fs::read_to_string(path) + .map_err(|e| format!("Error reading file {}: {}", path, e))?; match self.lua.load(&code).set_name(path).exec() { Ok(_) => (), Err(e) => {