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

            
12
use wasmtime::{AnyRef, ArrayRef, Caller, Linker, Rooted};
13

            
14
use crate::session::SessionData;
15

            
16
pub const REGISTERED_COMMANDS: &[&str] = &["error"];
17

            
18
236810
pub fn register(linker: &mut Linker<SessionData>) -> wasmtime::Result<()> {
19
236810
    linker.func_wrap(
20
236810
        "nomi",
21
236810
        "__nomi_raise",
22
        |mut caller: Caller<'_, SessionData>,
23
         code: Option<Rooted<ArrayRef>>,
24
         message: Option<Rooted<ArrayRef>>,
25
         detail: Option<Rooted<AnyRef>>|
26
13223
         -> wasmtime::Result<()> {
27
13223
            scripting::runtime::nomi_raise(&mut caller, code, message, detail)
28
13223
        },
29
    )?;
30
236810
    Ok(())
31
236810
}