Skip to content

Commit

Permalink
add more informative error
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
brentp committed Feb 19, 2025
1 parent 14305b1 commit 3ce774a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/vcfexpress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -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<dyn std::error::Error>> {
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) => {
Expand Down

0 comments on commit 3ce774a

Please sign in to comment.