mirror of
https://github.com/fluencelabs/aquavm
synced 2025-04-24 23:02:16 +00:00
feat(execution-engine)!: add error-code invariant check for match/mismatch (#622)
This commit is contained in:
parent
d195152320
commit
33a9d9f32f
@ -39,6 +39,14 @@ pub enum CatchableError {
|
||||
#[error("Local service error, ret_code is {0}, error message is '{1}'")]
|
||||
LocalServiceError(i32, Rc<String>),
|
||||
|
||||
/// This error type is produced by a match to notify xor that compared values aren't equal.
|
||||
#[error("match is used without corresponding xor")]
|
||||
MatchValuesNotEqual,
|
||||
|
||||
/// This error type is produced by a mismatch to notify xor that compared values aren't equal.
|
||||
#[error("mismatch is used without corresponding xor")]
|
||||
MismatchValuesEqual,
|
||||
|
||||
/// Variable with such a name wasn't defined during AIR script execution.
|
||||
/// This error type is used in order to support the join behaviour and
|
||||
/// it's ok if some variable hasn't been defined yet, due to the par nature of AIR.
|
||||
@ -59,14 +67,6 @@ pub enum CatchableError {
|
||||
#[error("expression '{1}' returned non-array value '{0}' for fold iterable")]
|
||||
FoldIteratesOverNonArray(JValue, String),
|
||||
|
||||
/// This error type is produced by a match to notify xor that compared values aren't equal.
|
||||
#[error("match is used without corresponding xor")]
|
||||
MatchValuesNotEqual,
|
||||
|
||||
/// This error type is produced by a mismatch to notify xor that compared values aren't equal.
|
||||
#[error("mismatch is used without corresponding xor")]
|
||||
MismatchValuesEqual,
|
||||
|
||||
/// This error type is produced by a fail instruction.
|
||||
#[error("fail with '{error}' is used without corresponding xor")]
|
||||
UserError { error: Rc<JValue> },
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
use air::CatchableError;
|
||||
use air::ExecutionCidState;
|
||||
use air::ToErrorCode;
|
||||
use air::NO_ERROR_ERROR_CODE;
|
||||
use air::NO_ERROR_MESSAGE;
|
||||
use air_test_framework::AirScriptExecutor;
|
||||
@ -297,6 +298,7 @@ fn match_without_xor() {
|
||||
let result = call_vm!(vm, <_>::default(), &script, "", result.data);
|
||||
|
||||
let expected_error = CatchableError::MatchValuesNotEqual;
|
||||
assert_eq!(expected_error.to_error_code(), 10001);
|
||||
assert!(check_error(&result, expected_error));
|
||||
|
||||
let result = call_vm!(vm, <_>::default(), script, "", result.data);
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
use air::CatchableError;
|
||||
use air::ToErrorCode;
|
||||
use air_test_utils::prelude::*;
|
||||
|
||||
#[test]
|
||||
@ -159,6 +160,7 @@ fn mismatch_without_xor() {
|
||||
let result = call_vm!(vm, <_>::default(), &script, "", result.data);
|
||||
|
||||
let expected_error = CatchableError::MismatchValuesEqual;
|
||||
assert_eq!(expected_error.to_error_code(), 10002);
|
||||
assert!(check_error(&result, expected_error));
|
||||
|
||||
let result = call_vm!(vm, <_>::default(), script, "", result.data);
|
||||
|
@ -210,15 +210,17 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_call_result_error() {
|
||||
let script = r#"
|
||||
(seq
|
||||
(call "peer1" ("service" "func") [] arg) ; err = {"ret_code":12,"result":"ERROR MESSAGE"}
|
||||
(call "peer2" ("service" "func") [arg]) ; ok = 43
|
||||
)
|
||||
"#;
|
||||
let exec = AirScriptExecutor::<NativeAirRunner>::new(
|
||||
TestRunParameters::from_init_peer_id("init_peer_id"),
|
||||
vec![],
|
||||
std::iter::empty(),
|
||||
r#"(seq
|
||||
(call "peer1" ("service" "func") [] arg) ; err = {"ret_code":12,"result":"ERROR MESSAGE"}
|
||||
(call "peer2" ("service" "func") [arg]) ; ok = 43
|
||||
)
|
||||
"#,
|
||||
script,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user