Lines
100 %
Functions
Branches
use server::command::CmdError;
use wasmtime::Error as WasmError;
use super::{TemplateError, runtime_error, validate_source};
use crate::host_failure::cmd_failure;
fn wrapped(err: WasmError) -> WasmError {
err.context("error while executing at wasm backtrace")
}
#[test]
fn database_failure_is_a_host_error() {
let err = wrapped(cmd_failure(
"get-commodity",
CmdError::DB(sqlx::Error::Protocol("x".into())),
));
let classified = runtime_error(&err);
assert!(
matches!(classified, TemplateError::Host(_)),
"{classified:?}"
);
assert!(classified.is_internal());
fn an_unreachable_database_is_an_unavailable_template_error() {
CmdError::DB(sqlx::Error::PoolTimedOut),
matches!(classified, TemplateError::Unavailable(_)),
fn bad_arguments_stay_a_user_runtime_error() {
let err = wrapped(cmd_failure("get-commodity", CmdError::Args("bad".into())));
matches!(classified, TemplateError::Runtime(_)),
assert!(!classified.is_internal());
fn script_raised_error_stays_a_user_runtime_error() {
let err = wrapped(WasmError::new(scripting::runtime::ScriptRaise {
code: "my-code".into(),
message: "boom".into(),
detail: None,
}));
matches!(&classified, TemplateError::Runtime(m) if m == "my-code: boom"),
fn a_thrown_host_condition_keeps_its_plain_message() {
code: "NOT-FOUND".into(),
message: "Commodity not found".into(),
matches!(&classified, TemplateError::Runtime(m) if m == "Commodity not found"),
fn only_engine_and_host_errors_are_internal() {
assert!(TemplateError::Engine(String::new()).is_internal());
assert!(TemplateError::Host(String::new()).is_internal());
assert!(!TemplateError::Compile(String::new()).is_internal());
assert!(!TemplateError::Runtime(String::new()).is_internal());
fn a_compiling_source_is_valid() {
assert_eq!(validate_source("(set-draft-note \"x\")"), Ok(()));
fn a_failing_source_is_refused_with_the_compile_message() {
let message = validate_source("(unclosed").unwrap_err();
message.starts_with("Template does not compile: template compile error: "),
"{message}"
fn a_native_off_the_render_surface_is_refused() {
let message = validate_source("(create-transaction \"x\")").unwrap_err();
message.starts_with("Template does not compile: "),