Do not print warning in xor for match/mismatch (#91)

This commit is contained in:
vms 2021-04-15 13:51:52 +03:00 committed by GitHub
parent 3d59e6f33e
commit ecd97a2360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 2 deletions

View File

@ -46,9 +46,9 @@ mod tests {
use crate::contexts::execution_trace::ExecutionTrace;
use crate::JValue;
use aqua_test_utils::call_vm;
use aqua_test_utils::create_aqua_vm;
use aqua_test_utils::echo_string_call_service;
use aqua_test_utils::{call_vm, set_variable_call_service};
use std::rc::Rc;
@ -194,4 +194,47 @@ mod tests {
assert_eq!(res.ret_code, 1015);
}
#[test]
fn match_with_two_xors() {
use crate::contexts::execution_trace::CallResult::*;
use crate::contexts::execution_trace::ExecutedState::*;
let local_peer_id = "local_peer_id";
let mut vm = create_aqua_vm(
set_variable_call_service(serde_json::json!(false).to_string()),
local_peer_id,
);
let local_peer_id_2 = "local_peer_id_2";
let script = format!(
r#"
(xor
(seq
(seq
(call "{0}" ("getDataSrv" "condition") [] condition)
(call "{0}" ("getDataSrv" "relay") [] relay)
)
(xor
(match condition true
(call "{0}" ("println" "print") ["it is true"])
)
(call "{1}" ("println" "print") ["it is false"])
)
)
(call "{0}" ("errorHandlingSrv" "error") [%last_error%])
)
"#,
local_peer_id, local_peer_id_2
);
let res = call_vm!(vm, "", script, "", "");
let mut trace: ExecutionTrace =
serde_json::from_slice(&res.data).expect("the interpreter should provide correct trace");
let expected_executed_call_result = Call(RequestSentBy(local_peer_id.to_string()));
assert_eq!(res.ret_code, 0);
assert_eq!(trace.pop_back().unwrap(), expected_executed_call_result);
}
}

View File

@ -49,6 +49,7 @@ mod tests {
use aqua_test_utils::call_vm;
use aqua_test_utils::create_aqua_vm;
use aqua_test_utils::echo_string_call_service;
use aqua_test_utils::set_variable_call_service;
use std::rc::Rc;
@ -194,4 +195,47 @@ mod tests {
assert_eq!(res.ret_code, 1016);
}
#[test]
fn mismatch_with_two_xors() {
use crate::contexts::execution_trace::CallResult::*;
use crate::contexts::execution_trace::ExecutedState::*;
let local_peer_id = "local_peer_id";
let mut vm = create_aqua_vm(
set_variable_call_service(serde_json::json!(false).to_string()),
local_peer_id,
);
let local_peer_id_2 = "local_peer_id_2";
let script = format!(
r#"
(xor
(seq
(seq
(call "{0}" ("getDataSrv" "condition") [] condition)
(call "{0}" ("getDataSrv" "relay") [] relay)
)
(xor
(mismatch condition true
(call "{1}" ("println" "print") ["it is false"])
)
(call "{0}" ("println" "print") ["it is true"])
)
)
(call "{0}" ("errorHandlingSrv" "error") [%last_error%])
)
"#,
local_peer_id, local_peer_id_2
);
let res = call_vm!(vm, "", script, "", "");
let mut trace: ExecutionTrace =
serde_json::from_slice(&res.data).expect("the interpreter should provide correct trace");
let expected_executed_call_result = Call(RequestSentBy(local_peer_id.to_string()));
assert_eq!(res.ret_code, 0);
assert_eq!(trace.pop_back().unwrap(), expected_executed_call_result);
}
}

View File

@ -31,7 +31,7 @@ impl<'i> super::ExecutableInstruction<'i> for Xor<'i> {
Err(e) if is_catchable_by_xor(&e) => {
exec_ctx.subtree_complete = true;
exec_ctx.last_error_could_be_set = true;
log::warn!("xor caught an error: {}", e);
print_xor_log(&e);
self.1.execute(exec_ctx, trace_ctx)
}
@ -46,6 +46,17 @@ fn is_catchable_by_xor(exec_error: &ExecutionError) -> bool {
!matches!(exec_error, ExecutionError::InvalidExecutedState(..))
}
fn print_xor_log(e: &ExecutionError) {
match e {
// These errors actually aren't real errors, but a way to bubble execution up from match
// to a corresponding xor. They'll become errors iff there is no such xor and execution is
// bubble up until the very beginning of current subtree. So the error message shouldn't
// be print out in order not to confuse users.
ExecutionError::MatchWithoutXorError | ExecutionError::MismatchWithoutXorError => {}
e => log::warn!("xor caught an error: {}", e),
}
}
#[cfg(test)]
mod tests {
use crate::contexts::execution_trace::ExecutionTrace;