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

@@ -5,9 +5,7 @@ use super::call::FnCallArgs;
use crate::ast::ScriptFnDef;
use crate::engine::{EvalState, Imports};
use crate::r#unsafe::unsafe_cast_var_name_to_lifetime;
use crate::{
Dynamic, Engine, EvalAltResult, Module, Position, RhaiError, RhaiResult, Scope, StaticVec,
};
use crate::{Dynamic, Engine, Module, Position, RhaiError, RhaiResult, Scope, StaticVec, ERR};
use std::mem;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@@ -44,7 +42,7 @@ impl Engine {
err: RhaiError,
pos: Position,
) -> RhaiResult {
Err(EvalAltResult::ErrorInFunctionCall(
Err(ERR::ErrorInFunctionCall(
name,
fn_def
.lib
@@ -70,7 +68,7 @@ impl Engine {
// Check for stack overflow
#[cfg(not(feature = "unchecked"))]
if level > self.max_call_levels() {
return Err(EvalAltResult::ErrorStackOverflow(pos).into());
return Err(ERR::ErrorStackOverflow(pos).into());
}
let orig_scope_len = scope.len();
@@ -131,9 +129,9 @@ impl Engine {
)
.or_else(|err| match *err {
// Convert return statement to return value
EvalAltResult::Return(x, _) => Ok(x),
ERR::Return(x, _) => Ok(x),
// Error in sub function call
EvalAltResult::ErrorInFunctionCall(name, src, err, _) => {
ERR::ErrorInFunctionCall(name, src, err, _) => {
let fn_name = if src.is_empty() {
format!("{} < {}", name, fn_def.name)
} else {