mirror of
https://github.com/fluencelabs/aquavm
synced 2025-04-25 07:12: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}'")]
|
#[error("Local service error, ret_code is {0}, error message is '{1}'")]
|
||||||
LocalServiceError(i32, Rc<String>),
|
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.
|
/// 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
|
/// 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.
|
/// 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")]
|
#[error("expression '{1}' returned non-array value '{0}' for fold iterable")]
|
||||||
FoldIteratesOverNonArray(JValue, String),
|
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.
|
/// This error type is produced by a fail instruction.
|
||||||
#[error("fail with '{error}' is used without corresponding xor")]
|
#[error("fail with '{error}' is used without corresponding xor")]
|
||||||
UserError { error: Rc<JValue> },
|
UserError { error: Rc<JValue> },
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
use air::CatchableError;
|
use air::CatchableError;
|
||||||
use air::ExecutionCidState;
|
use air::ExecutionCidState;
|
||||||
|
use air::ToErrorCode;
|
||||||
use air::NO_ERROR_ERROR_CODE;
|
use air::NO_ERROR_ERROR_CODE;
|
||||||
use air::NO_ERROR_MESSAGE;
|
use air::NO_ERROR_MESSAGE;
|
||||||
use air_test_framework::AirScriptExecutor;
|
use air_test_framework::AirScriptExecutor;
|
||||||
@ -297,6 +298,7 @@ fn match_without_xor() {
|
|||||||
let result = call_vm!(vm, <_>::default(), &script, "", result.data);
|
let result = call_vm!(vm, <_>::default(), &script, "", result.data);
|
||||||
|
|
||||||
let expected_error = CatchableError::MatchValuesNotEqual;
|
let expected_error = CatchableError::MatchValuesNotEqual;
|
||||||
|
assert_eq!(expected_error.to_error_code(), 10001);
|
||||||
assert!(check_error(&result, expected_error));
|
assert!(check_error(&result, expected_error));
|
||||||
|
|
||||||
let result = call_vm!(vm, <_>::default(), script, "", result.data);
|
let result = call_vm!(vm, <_>::default(), script, "", result.data);
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use air::CatchableError;
|
use air::CatchableError;
|
||||||
|
use air::ToErrorCode;
|
||||||
use air_test_utils::prelude::*;
|
use air_test_utils::prelude::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -159,6 +160,7 @@ fn mismatch_without_xor() {
|
|||||||
let result = call_vm!(vm, <_>::default(), &script, "", result.data);
|
let result = call_vm!(vm, <_>::default(), &script, "", result.data);
|
||||||
|
|
||||||
let expected_error = CatchableError::MismatchValuesEqual;
|
let expected_error = CatchableError::MismatchValuesEqual;
|
||||||
|
assert_eq!(expected_error.to_error_code(), 10002);
|
||||||
assert!(check_error(&result, expected_error));
|
assert!(check_error(&result, expected_error));
|
||||||
|
|
||||||
let result = call_vm!(vm, <_>::default(), script, "", result.data);
|
let result = call_vm!(vm, <_>::default(), script, "", result.data);
|
||||||
|
@ -210,15 +210,17 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_call_result_error() {
|
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(
|
let exec = AirScriptExecutor::<NativeAirRunner>::new(
|
||||||
TestRunParameters::from_init_peer_id("init_peer_id"),
|
TestRunParameters::from_init_peer_id("init_peer_id"),
|
||||||
vec![],
|
vec![],
|
||||||
std::iter::empty(),
|
std::iter::empty(),
|
||||||
r#"(seq
|
script,
|
||||||
(call "peer1" ("service" "func") [] arg) ; err = {"ret_code":12,"result":"ERROR MESSAGE"}
|
|
||||||
(call "peer2" ("service" "func") [arg]) ; ok = 43
|
|
||||||
)
|
|
||||||
"#,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user