uni_plugin_extism/error.rs
1//! Error types for the Extism loader.
2
3use thiserror::Error;
4
5/// Errors specific to the Extism loader.
6///
7/// Mirrors `uni_plugin_wasm::WasmError` in shape so the two loaders
8/// surface comparable failure modes despite their different ABIs.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum ExtismError {
12 /// The supplied WASM bytes failed to parse or did not declare the
13 /// expected Extism plugin shape (manifest export, function exports).
14 #[error("extism plugin: invalid wasm or manifest: {0}")]
15 InvalidPlugin(String),
16
17 /// The plugin's declared manifest did not pass validation
18 /// (unknown ABI, missing required fields, capability conflict).
19 #[error("extism plugin manifest invalid: {0}")]
20 ManifestInvalid(String),
21
22 /// Extism plugin instantiation failed.
23 #[error("extism instantiation failed: {0}")]
24 Instantiate(String),
25
26 /// A capability-gated host function was invoked without the matching
27 /// grant. Unlike the Component Model path (where the import is
28 /// absent at the linker level), Extism enforces capability checks at
29 /// the host-fn body — this variant carries the call that was
30 /// blocked.
31 #[error("extism plugin called host fn `{host_fn}` without {capability:?} grant")]
32 CapabilityDenied {
33 /// Host function the plugin attempted to invoke.
34 host_fn: String,
35 /// The capability the plugin would need.
36 capability: String,
37 },
38
39 /// The plugin's output failed to decode under the expected wire
40 /// format (JSON or MessagePack for control surfaces).
41 #[error("extism output decode error: {0}")]
42 OutputDecode(String),
43
44 /// Arrow IPC encode / decode failed across the wasm boundary.
45 /// Distinct from [`Self::OutputDecode`] which is JSON / MessagePack
46 /// for control surfaces.
47 #[error("extism arrow IPC: {0}")]
48 Ipc(#[from] uni_plugin_wasm_rt::IpcError),
49
50 /// Wall-clock, fuel, or memory limit exceeded.
51 #[error("extism plugin exceeded resource limit: {0}")]
52 ResourceLimit(String),
53
54 /// Internal / unexpected error.
55 #[error("uni-plugin-extism internal error: {0}")]
56 Internal(String),
57}
58
59impl uni_plugin_wasm_rt::pool::PoolResourceLimit for ExtismError {
60 fn resource_limit(msg: String) -> Self {
61 Self::ResourceLimit(msg)
62 }
63}