Expand description
(catch-each items var body) host native — Tier 2’s iteration-
bounded error recovery (ADR-0025).
Compiler-side lowering: the body is wrapped as a single-arg lambda
and lifted to a real wasm fn via Tier 1.5’s closure machinery. The
call site extracts (funcref, env_anyref) from the $closure_<sig>
struct and pushes them alongside the items pair-list, then emits
call $__nomi_catch_each. The host walks the items chain in Rust:
per element it invokes the funcref via Func::call_async with
(env, item) args, recovers wasmtime::Error, classifies it, and
collects the per-call outcome as a heterogeneous result cell.
Each result cell is a list head: (ok value) for normal returns
and (err code msg) for script-raised / engine-classified errors.
Both ride $pair chains whose cars are anyref, so the resulting
list is pair<anyref>; consumers reach into a cell with the
standard CAR / CADR / CADDR accessors.
Engine-managed traps are not catchable: when
classify_runtime_error returns OutOfFuel or EpochInterrupt, the
host fn re-throws the original error so it bubbles past catch-each
to the outer caller. This rule is the load-bearing reason the fuel /
epoch budgets continue to bound a hostile script — without it, a
script could wrap an infinite loop in catch-each and keep running
past the deadline.