Lines
95 %
Functions
100 %
Branches
//! A raise detail decodes as contents, so a cyclic or too deep value carries
//! the depth placeholder instead of losing the whole detail.
use scripting::HookError;
use scripting::executor::ScriptExecutor;
use scripting::format::{ContextType, EntityType};
use scripting::runtime::{EngineError, classify_runtime_error};
use scripting::serializer::MemorySerializer;
use nomiscript::{Compiler, Program, Reader, SymbolTable, Value, format_value};
fn raised_detail(src: &str) -> Option<String> {
let program: Program = Reader::parse(src).expect("parse script source");
let mut compiler = Compiler::with_host_fns(Vec::new());
let mut symbols = SymbolTable::with_builtins_for_wasm();
let wasm = compiler
.compile(&program, &mut symbols)
.expect("script compiles");
let mut ser = MemorySerializer::new();
ser.set_context(ContextType::BatchProcess, EntityType::Transaction);
let input = ser.finalize(4096);
let executor = ScriptExecutor::try_new().expect("baseline engine");
let Err(HookError::WASM(err)) = executor.execute(&wasm, &input, Some(4096)) else {
panic!("uncaught (error) must surface as a wasm error");
};
match classify_runtime_error(&err) {
EngineError::ScriptRaised { detail, .. } => detail.map(|d| format_value(&Value::from(d))),
other => panic!("expected ScriptRaised, got {other:?}"),
}
fn assert_placeholder(detail: Option<String>) {
let detail = detail.expect("the raise carries a detail");
assert!(detail.contains("#<...>"), "{detail}");
assert!(!detail.contains("undecodable"), "{detail}");
#[test]
fn a_cyclic_struct_detail_prints_the_placeholder() {
assert_placeholder(raised_detail(
r#"(defstruct node next) (defvar *n* (make-node)) (setf (node-next *n*) *n*)
(error 'boom "c" *n*)"#,
));
fn a_deep_struct_chain_detail_prints_the_placeholder() {
r#"(defstruct node next)
(defun chain (n acc) (if (= n 0) acc (chain (- n 1) (make-node :next acc))))
(error 'boom "c" (chain 63 nil))"#,
fn a_deep_list_detail_prints_the_placeholder() {
r#"(let ((x (list 1 "a"))) (do ((i 0 (+ i 1))) ((= i 63)) (setf x (list x))) (error 'boom "c" x))"#,