Deprecate From<EvalAltResult> for Result<T, Box<EvalAltResult>> because it is clearer for code to explicitly wrap errors in Err.
This commit is contained in:
@@ -79,8 +79,11 @@ mod array_functions {
|
||||
// Check if array will be over max size limit
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if _ctx.engine().max_array_size() > 0 && (len as usize) > _ctx.engine().max_array_size() {
|
||||
return EvalAltResult::ErrorDataTooLarge("Size of array".to_string(), Position::NONE)
|
||||
.into();
|
||||
return Err(EvalAltResult::ErrorDataTooLarge(
|
||||
"Size of array".to_string(),
|
||||
Position::NONE,
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
if len as usize > array.len() {
|
||||
@@ -267,13 +270,13 @@ mod array_functions {
|
||||
ctx.call_fn_raw(fn_name, true, false, &mut args)?
|
||||
}
|
||||
_ => {
|
||||
return EvalAltResult::ErrorInFunctionCall(
|
||||
"drain".to_string(),
|
||||
return Err(EvalAltResult::ErrorInFunctionCall(
|
||||
"map".to_string(),
|
||||
ctx.source().unwrap_or("").to_string(),
|
||||
err,
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -309,13 +312,13 @@ mod array_functions {
|
||||
ctx.call_fn_raw(fn_name, true, false, &mut args)?
|
||||
}
|
||||
_ => {
|
||||
return EvalAltResult::ErrorInFunctionCall(
|
||||
"drain".to_string(),
|
||||
return Err(EvalAltResult::ErrorInFunctionCall(
|
||||
"filter".to_string(),
|
||||
ctx.source().unwrap_or("").to_string(),
|
||||
err,
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -473,13 +476,13 @@ mod array_functions {
|
||||
ctx.call_fn_raw(fn_name, true, false, &mut args)?
|
||||
}
|
||||
_ => {
|
||||
return EvalAltResult::ErrorInFunctionCall(
|
||||
"drain".to_string(),
|
||||
return Err(EvalAltResult::ErrorInFunctionCall(
|
||||
"index_of".to_string(),
|
||||
ctx.source().unwrap_or("").to_string(),
|
||||
err,
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -519,13 +522,13 @@ mod array_functions {
|
||||
ctx.call_fn_raw(fn_name, true, false, &mut args)?
|
||||
}
|
||||
_ => {
|
||||
return EvalAltResult::ErrorInFunctionCall(
|
||||
"drain".to_string(),
|
||||
return Err(EvalAltResult::ErrorInFunctionCall(
|
||||
"some".to_string(),
|
||||
ctx.source().unwrap_or("").to_string(),
|
||||
err,
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -565,13 +568,13 @@ mod array_functions {
|
||||
ctx.call_fn_raw(fn_name, true, false, &mut args)?
|
||||
}
|
||||
_ => {
|
||||
return EvalAltResult::ErrorInFunctionCall(
|
||||
"drain".to_string(),
|
||||
return Err(EvalAltResult::ErrorInFunctionCall(
|
||||
"all".to_string(),
|
||||
ctx.source().unwrap_or("").to_string(),
|
||||
err,
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -781,13 +784,13 @@ mod array_functions {
|
||||
ctx.call_fn_raw(fn_name, true, false, &mut args)?
|
||||
}
|
||||
_ => {
|
||||
return EvalAltResult::ErrorInFunctionCall(
|
||||
return Err(EvalAltResult::ErrorInFunctionCall(
|
||||
"drain".to_string(),
|
||||
ctx.source().unwrap_or("").to_string(),
|
||||
err,
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -875,13 +878,13 @@ mod array_functions {
|
||||
ctx.call_fn_raw(fn_name, true, false, &mut args)?
|
||||
}
|
||||
_ => {
|
||||
return EvalAltResult::ErrorInFunctionCall(
|
||||
"drain".to_string(),
|
||||
return Err(EvalAltResult::ErrorInFunctionCall(
|
||||
"retain".to_string(),
|
||||
ctx.source().unwrap_or("").to_string(),
|
||||
err,
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ where
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if let Some(r) = from.checked_add(&step) {
|
||||
if r == from {
|
||||
return EvalAltResult::ErrorInFunctionCall(
|
||||
return Err(EvalAltResult::ErrorInFunctionCall(
|
||||
"range".to_string(),
|
||||
Default::default(),
|
||||
EvalAltResult::ErrorArithmetic(
|
||||
@@ -35,7 +35,7 @@ where
|
||||
.into(),
|
||||
crate::Position::NONE,
|
||||
)
|
||||
.into();
|
||||
.into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,21 +122,27 @@ impl BitRange {
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if offset >= BITS {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
|
||||
.into();
|
||||
return Err(
|
||||
EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE).into(),
|
||||
);
|
||||
}
|
||||
offset
|
||||
} else {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if let Some(abs_from) = from.checked_abs() {
|
||||
if (abs_from as usize) > BITS {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
|
||||
.into();
|
||||
return Err(EvalAltResult::ErrorBitFieldBounds(
|
||||
BITS,
|
||||
from,
|
||||
crate::Position::NONE,
|
||||
)
|
||||
.into());
|
||||
}
|
||||
BITS - (abs_from as usize)
|
||||
} else {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
|
||||
.into();
|
||||
return Err(
|
||||
EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE).into(),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "unchecked")]
|
||||
@@ -325,10 +331,10 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
||||
pub fn new(from: FLOAT, to: FLOAT, step: FLOAT) -> Result<Self, Box<EvalAltResult>> {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if step == 0.0 {
|
||||
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
|
||||
return Err(EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
|
||||
EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE).into(),
|
||||
crate::Position::NONE,
|
||||
).into();
|
||||
).into());
|
||||
}
|
||||
|
||||
Ok(Self(from, to, step))
|
||||
@@ -387,10 +393,10 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
||||
pub fn new(from: Decimal, to: Decimal, step: Decimal) -> Result<Self, Box<EvalAltResult>> {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if step.is_zero() {
|
||||
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
|
||||
return Err(EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
|
||||
EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE).into(),
|
||||
crate::Position::NONE,
|
||||
).into();
|
||||
).into());
|
||||
}
|
||||
|
||||
Ok(Self(from, to, step))
|
||||
|
@@ -14,7 +14,7 @@ mod core_functions {
|
||||
#[rhai_fn(name = "set_tag", set = "tag", return_raw)]
|
||||
pub fn set_tag(value: &mut Dynamic, tag: INT) -> Result<(), Box<EvalAltResult>> {
|
||||
if tag < Tag::MIN as INT {
|
||||
EvalAltResult::ErrorArithmetic(
|
||||
Err(EvalAltResult::ErrorArithmetic(
|
||||
format!(
|
||||
"{} is too small to fit into a tag (must be between {} and {})",
|
||||
tag,
|
||||
@@ -23,9 +23,9 @@ mod core_functions {
|
||||
),
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
} else if tag > Tag::MAX as INT {
|
||||
EvalAltResult::ErrorArithmetic(
|
||||
Err(EvalAltResult::ErrorArithmetic(
|
||||
format!(
|
||||
"{} is too large to fit into a tag (must be between {} and {})",
|
||||
tag,
|
||||
@@ -34,7 +34,7 @@ mod core_functions {
|
||||
),
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
} else {
|
||||
value.set_tag(tag as Tag);
|
||||
Ok(())
|
||||
|
@@ -202,7 +202,7 @@ mod bit_field_functions {
|
||||
let offset = index as usize;
|
||||
|
||||
if offset >= BITS {
|
||||
EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()
|
||||
Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into())
|
||||
} else {
|
||||
Ok((value & (1 << offset)) != 0)
|
||||
}
|
||||
@@ -211,12 +211,12 @@ mod bit_field_functions {
|
||||
|
||||
// Count from end if negative
|
||||
if offset > BITS {
|
||||
EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()
|
||||
Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into())
|
||||
} else {
|
||||
Ok((value & (1 << (BITS - offset))) != 0)
|
||||
}
|
||||
} else {
|
||||
EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()
|
||||
Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into())
|
||||
}
|
||||
}
|
||||
#[rhai_fn(return_raw)]
|
||||
@@ -225,7 +225,7 @@ mod bit_field_functions {
|
||||
let offset = index as usize;
|
||||
|
||||
if offset >= BITS {
|
||||
EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()
|
||||
Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into())
|
||||
} else {
|
||||
let mask = 1 << offset;
|
||||
if new_value {
|
||||
@@ -240,7 +240,7 @@ mod bit_field_functions {
|
||||
|
||||
// Count from end if negative
|
||||
if offset > BITS {
|
||||
EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()
|
||||
Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into())
|
||||
} else {
|
||||
let mask = 1 << offset;
|
||||
if new_value {
|
||||
@@ -251,7 +251,7 @@ mod bit_field_functions {
|
||||
Ok(())
|
||||
}
|
||||
} else {
|
||||
EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()
|
||||
Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into())
|
||||
}
|
||||
}
|
||||
#[rhai_fn(return_raw)]
|
||||
@@ -264,7 +264,7 @@ mod bit_field_functions {
|
||||
let offset = index as usize;
|
||||
|
||||
if offset >= BITS {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into();
|
||||
return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into());
|
||||
}
|
||||
|
||||
offset
|
||||
@@ -273,11 +273,11 @@ mod bit_field_functions {
|
||||
|
||||
// Count from end if negative
|
||||
if offset > BITS {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into();
|
||||
return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into());
|
||||
}
|
||||
BITS - offset
|
||||
} else {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into();
|
||||
return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into());
|
||||
};
|
||||
|
||||
let bits = if offset + bits as usize > BITS {
|
||||
@@ -311,7 +311,7 @@ mod bit_field_functions {
|
||||
let offset = index as usize;
|
||||
|
||||
if offset >= BITS {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into();
|
||||
return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into());
|
||||
}
|
||||
|
||||
offset
|
||||
@@ -320,11 +320,11 @@ mod bit_field_functions {
|
||||
|
||||
// Count from end if negative
|
||||
if offset > BITS {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into();
|
||||
return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into());
|
||||
}
|
||||
BITS - offset
|
||||
} else {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into();
|
||||
return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into());
|
||||
};
|
||||
|
||||
let bits = if offset + bits as usize > BITS {
|
||||
|
@@ -114,11 +114,11 @@ mod int_functions {
|
||||
#[rhai_fn(name = "parse_int", return_raw)]
|
||||
pub fn parse_int_radix(string: &str, radix: INT) -> Result<INT, Box<EvalAltResult>> {
|
||||
if !(2..=36).contains(&radix) {
|
||||
return EvalAltResult::ErrorArithmetic(
|
||||
return Err(EvalAltResult::ErrorArithmetic(
|
||||
format!("Invalid radix: '{}'", radix),
|
||||
Position::NONE,
|
||||
)
|
||||
.into();
|
||||
.into());
|
||||
}
|
||||
|
||||
INT::from_str_radix(string.trim(), radix as u32).map_err(|err| {
|
||||
@@ -261,11 +261,11 @@ mod float_functions {
|
||||
#[rhai_fn(name = "to_int", return_raw)]
|
||||
pub fn f32_to_int(x: f32) -> Result<INT, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f32) {
|
||||
EvalAltResult::ErrorArithmetic(
|
||||
Err(EvalAltResult::ErrorArithmetic(
|
||||
format!("Integer overflow: to_int({})", x),
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
} else {
|
||||
Ok(x.trunc() as INT)
|
||||
}
|
||||
@@ -273,11 +273,11 @@ mod float_functions {
|
||||
#[rhai_fn(name = "to_int", return_raw)]
|
||||
pub fn f64_to_int(x: f64) -> Result<INT, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f64) {
|
||||
EvalAltResult::ErrorArithmetic(
|
||||
Err(EvalAltResult::ErrorArithmetic(
|
||||
format!("Integer overflow: to_int({})", x),
|
||||
Position::NONE,
|
||||
)
|
||||
.into()
|
||||
.into())
|
||||
} else {
|
||||
Ok(x.trunc() as INT)
|
||||
}
|
||||
|
@@ -471,11 +471,11 @@ mod string_functions {
|
||||
// Check if string will be over max size limit
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() {
|
||||
return crate::EvalAltResult::ErrorDataTooLarge(
|
||||
return Err(crate::EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
crate::Position::NONE,
|
||||
)
|
||||
.into();
|
||||
.into());
|
||||
}
|
||||
|
||||
let orig_len = string.chars().count();
|
||||
@@ -490,11 +490,11 @@ mod string_functions {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if _ctx.engine().max_string_size() > 0 && string.len() > _ctx.engine().max_string_size()
|
||||
{
|
||||
return crate::EvalAltResult::ErrorDataTooLarge(
|
||||
return Err(crate::EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
crate::Position::NONE,
|
||||
)
|
||||
.into();
|
||||
.into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,11 +516,11 @@ mod string_functions {
|
||||
// Check if string will be over max size limit
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() {
|
||||
return crate::EvalAltResult::ErrorDataTooLarge(
|
||||
return Err(crate::EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
crate::Position::NONE,
|
||||
)
|
||||
.into();
|
||||
.into());
|
||||
}
|
||||
|
||||
let mut str_len = string.chars().count();
|
||||
@@ -542,11 +542,11 @@ mod string_functions {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if _ctx.engine().max_string_size() > 0 && string.len() > _ctx.engine().max_string_size()
|
||||
{
|
||||
return crate::EvalAltResult::ErrorDataTooLarge(
|
||||
return Err(crate::EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
crate::Position::NONE,
|
||||
)
|
||||
.into();
|
||||
.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user