Use type alias for error.

This commit is contained in:
Stephen Chung
2021-12-27 12:27:31 +08:00
parent e7ca3f41dd
commit 05d4c81e7a
29 changed files with 293 additions and 378 deletions

View File

@@ -458,7 +458,7 @@ impl Module {
#[inline]
pub(crate) fn get_qualified_var(&self, hash_var: u64) -> RhaiResultOf<&Dynamic> {
self.all_variables.get(&hash_var).ok_or_else(|| {
crate::EvalAltResult::ErrorVariableNotFound(String::new(), crate::Position::NONE).into()
crate::ERR::ErrorVariableNotFound(String::new(), crate::Position::NONE).into()
})
}

View File

@@ -1,4 +1,4 @@
use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, RhaiResultOf, Shared};
use crate::{Engine,ERR, Module, ModuleResolver, Position, RhaiResultOf, Shared};
use std::ops::AddAssign;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@@ -128,14 +128,14 @@ impl ModuleResolver for ModuleResolversCollection {
match resolver.resolve(engine, source_path, path, pos) {
Ok(module) => return Ok(module),
Err(err) => match *err {
EvalAltResult::ErrorModuleNotFound(_, _) => continue,
EvalAltResult::ErrorInModule(_, err, _) => return Err(err),
ERR::ErrorModuleNotFound(_, _) => continue,
ERR::ErrorInModule(_, err, _) => return Err(err),
_ => panic!("ModuleResolver::resolve returns error that is not ErrorModuleNotFound or ErrorInModule"),
},
}
}
Err(EvalAltResult::ErrorModuleNotFound(path.into(), pos).into())
Err(ERR::ErrorModuleNotFound(path.into(), pos).into())
}
}

View File

@@ -1,4 +1,4 @@
use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, RhaiResultOf, Shared};
use crate::{Engine,ERR, Module, ModuleResolver, Position, RhaiResultOf, Shared};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@@ -45,6 +45,6 @@ impl ModuleResolver for DummyModuleResolver {
path: &str,
pos: Position,
) -> RhaiResultOf<Shared<Module>> {
Err(EvalAltResult::ErrorModuleNotFound(path.into(), pos).into())
Err(ERR::ErrorModuleNotFound(path.into(), pos).into())
}
}

View File

@@ -3,7 +3,7 @@
use crate::func::native::shared_write_lock;
use crate::{
Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, RhaiResultOf, Scope,
Engine,ERR, Identifier, Module, ModuleResolver, Position, RhaiResultOf, Scope,
Shared,
};
@@ -288,17 +288,17 @@ impl ModuleResolver for FileModuleResolver {
let mut ast = engine
.compile_file(file_path.clone())
.map_err(|err| match *err {
EvalAltResult::ErrorSystem(_, err) if err.is::<IoError>() => {
Box::new(EvalAltResult::ErrorModuleNotFound(path.to_string(), pos))
ERR::ErrorSystem(_, err) if err.is::<IoError>() => {
Box::new(ERR::ErrorModuleNotFound(path.to_string(), pos))
}
_ => Box::new(EvalAltResult::ErrorInModule(path.to_string(), err, pos)),
_ => Box::new(ERR::ErrorInModule(path.to_string(), err, pos)),
})?;
ast.set_source(path);
// Make a module from the AST
let m: Shared<Module> = Module::eval_ast_as_new(scope, &ast, engine)
.map_err(|err| Box::new(EvalAltResult::ErrorInModule(path.to_string(), err, pos)))?
.map_err(|err| Box::new(ERR::ErrorInModule(path.to_string(), err, pos)))?
.into();
// Put it into the cache
@@ -331,10 +331,10 @@ impl ModuleResolver for FileModuleResolver {
ast
})
.map_err(|err| match *err {
EvalAltResult::ErrorSystem(_, err) if err.is::<IoError>() => {
EvalAltResult::ErrorModuleNotFound(path.to_string(), pos).into()
ERR::ErrorSystem(_, err) if err.is::<IoError>() => {
ERR::ErrorModuleNotFound(path.to_string(), pos).into()
}
_ => EvalAltResult::ErrorInModule(path.to_string(), err, pos).into(),
_ => ERR::ErrorInModule(path.to_string(), err, pos).into(),
}),
)
}

View File

@@ -1,6 +1,5 @@
use crate::{
Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, RhaiResultOf, Shared,
SmartString,
Engine, Identifier, Module, ModuleResolver, Position, RhaiResultOf, Shared, SmartString, ERR,
};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@@ -136,7 +135,7 @@ impl ModuleResolver for StaticModuleResolver {
self.0
.get(path)
.cloned()
.ok_or_else(|| EvalAltResult::ErrorModuleNotFound(path.into(), pos).into())
.ok_or_else(|| ERR::ErrorModuleNotFound(path.into(), pos).into())
}
}