rpc/natives/raise.rs
1//! Script-raise host native: the boundary bridge for in-guest raises.
2//!
3//! Since Tier 3.2, `(error 'code "msg" [detail])` and engine errors (commodity
4//! mismatch) `throw $nomi_error` in-guest; this host fn is not the raise
5//! primitive but the BOUNDARY BRIDGE (ADR-0026): the compiler wraps each
6//! host-invoked body in a `try_table` that catches any uncaught `$nomi_error`,
7//! reads its `code`/`message`/`detail`, and `call $__nomi_raise`s here. The fn
8//! never returns normally; it always produces a [`scripting::runtime::ScriptRaise`]
9//! error that [`scripting::runtime::classify_runtime_error`] lifts into a
10//! `ScriptRaised { code, message, detail }` for the wire envelope.
11
12use wasmtime::{AnyRef, ArrayRef, Caller, Linker, Rooted};
13
14use crate::session::SessionData;
15
16pub const REGISTERED_COMMANDS: &[&str] = &["error"];
17
18pub fn register(linker: &mut Linker<SessionData>) -> wasmtime::Result<()> {
19 linker.func_wrap(
20 "nomi",
21 "__nomi_raise",
22 |mut caller: Caller<'_, SessionData>,
23 code: Option<Rooted<ArrayRef>>,
24 message: Option<Rooted<ArrayRef>>,
25 detail: Option<Rooted<AnyRef>>|
26 -> wasmtime::Result<()> {
27 scripting::runtime::nomi_raise(&mut caller, code, message, detail)
28 },
29 )?;
30 Ok(())
31}