Lines
100 %
Functions
Branches
use std::sync::{Arc, Mutex};
use crate::envelope::ErrorCode;
use scripting::runtime::{EngineOpts, build_engine, classify_runtime_error, compile_wat};
use uuid::Uuid;
use wasmtime::{Linker, Store};
use super::*;
use crate::host_failure::not_found_condition;
use crate::natives::native::register_native;
const WAT: &str = r#"
(module
(import "nomi" "missing" (func $missing))
(func (export "go") (call $missing)))
"#;
#[tokio::test(flavor = "current_thread")]
async fn a_condition_that_cannot_be_thrown_keeps_its_wire_code_and_plain_detail() {
let engine = build_engine(EngineOpts::baseline()).unwrap();
let mut linker: Linker<SessionData> = Linker::new(&engine);
register_native(&mut linker, "missing", |_caller, ()| {
Box::pin(async {
Err::<(), _>(not_found_condition(
"Account not found",
Some("set-account-tag".into()),
))
})
.unwrap();
let module = compile_wat(&engine, WAT).unwrap();
let data = SessionData::new(
ScriptCtx::new(Uuid::nil()),
Arc::new(Mutex::new(String::new())),
);
let mut store = Store::new(&engine, data);
store.set_epoch_deadline(1_000);
let instance = linker.instantiate_async(&mut store, &module).await.unwrap();
let go = instance.get_func(&mut store, "go").unwrap();
let err = go.call_async(&mut store, &[], &mut []).await.unwrap_err();
let response =
EvalFailure::Engine(RequestId::Int(11), classify_runtime_error(&err)).into_response();
assert_eq!(
response.payload,
ResponsePayload::Error {
code: ErrorCode::new("not-found"),
message: "Account not found".into(),
detail: Some(Value::String("set-account-tag".into())),
}