Wrap file module functions in ErrorInModule.
This commit is contained in:
parent
39bbff878c
commit
da9aa60256
@ -21,6 +21,7 @@ Breaking changes
|
|||||||
* `EvalAltResult` has a new variant `ErrorInModule` which holds errors when loading an external module.
|
* `EvalAltResult` has a new variant `ErrorInModule` which holds errors when loading an external module.
|
||||||
* `Module::eval_ast_as_new` now takes an extra boolean parameter, indicating whether to encapsulate the entire module into a separate namespace.
|
* `Module::eval_ast_as_new` now takes an extra boolean parameter, indicating whether to encapsulate the entire module into a separate namespace.
|
||||||
* Functions in `FileModuleResolver` loaded modules now can cross-call each other, but cannot access the global namespace. For the old behavior, use `MergingFileModuleResolver` instead.
|
* Functions in `FileModuleResolver` loaded modules now can cross-call each other, but cannot access the global namespace. For the old behavior, use `MergingFileModuleResolver` instead.
|
||||||
|
* New `EvalAltResult::ErrorInModule` variant capturing errors when loading a module from a script file.
|
||||||
|
|
||||||
New features
|
New features
|
||||||
------------
|
------------
|
||||||
|
@ -1280,13 +1280,22 @@ impl Module {
|
|||||||
name,
|
name,
|
||||||
num_args,
|
num_args,
|
||||||
move |engine: &Engine, _, args: &mut [&mut Dynamic]| {
|
move |engine: &Engine, _, args: &mut [&mut Dynamic]| {
|
||||||
engine.call_fn_dynamic_raw(
|
engine
|
||||||
|
.call_fn_dynamic_raw(
|
||||||
&mut Scope::new(),
|
&mut Scope::new(),
|
||||||
&ast_lib,
|
&ast_lib,
|
||||||
&fn_name,
|
&fn_name,
|
||||||
&mut None,
|
&mut None,
|
||||||
args,
|
args,
|
||||||
)
|
)
|
||||||
|
.map_err(|err| {
|
||||||
|
// Wrap the error in a module-error
|
||||||
|
Box::new(EvalAltResult::ErrorInModule(
|
||||||
|
"".to_string(),
|
||||||
|
err,
|
||||||
|
Position::none(),
|
||||||
|
))
|
||||||
|
})
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -184,6 +184,9 @@ impl fmt::Display for EvalAltResult {
|
|||||||
Self::ErrorInFunctionCall(s, err, _) => {
|
Self::ErrorInFunctionCall(s, err, _) => {
|
||||||
write!(f, "Error in call to function '{}': {}", s, err)?
|
write!(f, "Error in call to function '{}': {}", s, err)?
|
||||||
}
|
}
|
||||||
|
Self::ErrorInModule(s, err, _) if s.is_empty() => {
|
||||||
|
write!(f, "Error in module: {}", err)?
|
||||||
|
}
|
||||||
Self::ErrorInModule(s, err, _) => write!(f, "Error in module '{}': {}", s, err)?,
|
Self::ErrorInModule(s, err, _) => write!(f, "Error in module '{}': {}", s, err)?,
|
||||||
|
|
||||||
Self::ErrorFunctionNotFound(s, _)
|
Self::ErrorFunctionNotFound(s, _)
|
||||||
|
Loading…
Reference in New Issue
Block a user