diff --git a/fud2/fud-core/src/exec/driver.rs b/fud2/fud-core/src/exec/driver.rs index c4805ca7ee..34a04bc311 100644 --- a/fud2/fud-core/src/exec/driver.rs +++ b/fud2/fud-core/src/exec/driver.rs @@ -439,7 +439,10 @@ impl DriverBuilder { } /// Load any plugin scripts specified in the configuration file. - pub fn load_plugins(mut self, config_data: &figment::Figment) -> Self { + pub fn load_plugins( + mut self, + config_data: &figment::Figment, + ) -> anyhow::Result { // pull out things from self that we need let plugin_dir = self.scripts_dir.take(); let plugin_files = self.script_files.take(); @@ -455,7 +458,7 @@ impl DriverBuilder { .filter_map(|dir_entry| dir_entry.map(|p| p.path()).ok()) // filter out paths that don't have `.rhai` extension .filter(|p| p.extension() == Some(OsStr::new("rhai"))), - ); + )?; } // add static plugins (where string is included in binary) @@ -467,10 +470,10 @@ impl DriverBuilder { if let Ok(plugins) = config_data.extract_inner::>("plugins") { - runner.add_files(plugins.into_iter()); + runner.add_files(plugins.into_iter())?; } - runner.run() + Ok(runner.run()) } pub fn build(self) -> Driver { diff --git a/fud2/fud-core/src/script/plugin.rs b/fud2/fud-core/src/script/plugin.rs index 040e32db35..8aec4475fa 100644 --- a/fud2/fud-core/src/script/plugin.rs +++ b/fud2/fud-core/src/script/plugin.rs @@ -462,14 +462,24 @@ impl ScriptRunner { pub fn add_files( &mut self, files: impl Iterator, - ) -> &mut Self { + ) -> anyhow::Result<&mut Self> { for f in files { - let ast = self.engine.compile_file(f.clone()).unwrap(); + let res = self.engine.compile_file(f.clone()); + let ast = match res { + Err(e) => { + return Err(anyhow::format_err!( + "{} in {}", + e, + f.to_str().unwrap() + )) + } + Ok(ast) => ast, + }; let functions = self.resolver.as_mut().unwrap().register_path(f, ast); self.rhai_functions = self.rhai_functions.merge(&functions); } - self + Ok(self) } pub fn add_static_files( diff --git a/fud2/src/main.rs b/fud2/src/main.rs index 419939e729..16152eb1b9 100644 --- a/fud2/src/main.rs +++ b/fud2/src/main.rs @@ -41,7 +41,7 @@ fn main() -> anyhow::Result<()> { #[cfg(feature = "migrate_to_scripts")] { - bld = bld.load_plugins(&config); + bld = bld.load_plugins(&config)?; } let driver = bld.build(); diff --git a/fud2/tests/tests.rs b/fud2/tests/tests.rs index a936a3f928..a163dc4b9f 100644 --- a/fud2/tests/tests.rs +++ b/fud2/tests/tests.rs @@ -22,7 +22,7 @@ fn test_driver() -> Driver { let mut bld = DriverBuilder::new("fud2-plugins"); let config = figment::Figment::new(); bld.scripts_dir(manifest_dir_macros::directory_path!("scripts")); - bld.load_plugins(&config).build() + bld.load_plugins(&config).unwrap().build() } fn driver_from_path_with_config( @@ -36,7 +36,7 @@ fn driver_from_path_with_config( path ); bld.scripts_dir(&path); - bld.load_plugins(&config).build() + bld.load_plugins(&config).unwrap().build() } fn driver_from_path(path: &str) -> Driver {