1use graphrt_core::node::NodeError;
4
5#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
7#[non_exhaustive]
8pub enum WasmError {
9 #[error("reading plugin `{path}`: {message}")]
10 Io { path: String, message: String },
11 #[error("module is {size} bytes, above the {limit}-byte limit")]
12 ModuleTooLarge { size: usize, limit: usize },
13 #[error("invalid wasm module: {0}")]
14 InvalidModule(String),
15 #[error("instantiating module failed: {0}")]
16 Instantiate(String),
17 #[error("module does not export `{0}` with the expected signature")]
18 MissingExport(String),
19 #[error("module implements ABI version {found}, host supports {supported}")]
20 AbiVersion { found: i32, supported: i32 },
21 #[error("invalid plugin manifest: {0}")]
22 Manifest(String),
23 #[error("node kind `{0}` is declared more than once")]
24 DuplicateKind(String),
25 #[error("plugin does not implement node kind `{0}`")]
26 UnknownKind(String),
27 #[error("node kind `{0}` is already registered")]
28 KindConflict(String),
29 #[error("guest ran out of fuel (CPU budget exhausted)")]
30 FuelExhausted,
31 #[error("guest exceeded its memory limit")]
32 MemoryLimit,
33 #[error("guest trapped: {0}")]
34 Trap(String),
35 #[error("{what} is {size} bytes, above the {limit}-byte limit")]
36 TooLarge { what: &'static str, size: usize, limit: usize },
37 #[error("guest returned an out-of-bounds buffer (ptr {ptr}, len {len})")]
38 OutOfBounds { ptr: u32, len: u32 },
39 #[error("guest returned invalid output: {0}")]
40 InvalidOutput(String),
41 #[error("internal error: {0}")]
42 Internal(String),
43}
44
45impl WasmError {
46 pub fn kind(&self) -> &'static str {
48 match self {
49 WasmError::FuelExhausted => "wasm_fuel_exhausted",
50 WasmError::MemoryLimit => "wasm_memory_limit",
51 WasmError::Trap(_) => "wasm_trap",
52 WasmError::TooLarge { .. } | WasmError::OutOfBounds { .. } | WasmError::InvalidOutput(_) => {
53 "wasm_invalid_output"
54 }
55 WasmError::Internal(_) => "wasm_internal",
56 _ => "wasm_plugin",
57 }
58 }
59}
60
61impl From<WasmError> for NodeError {
62 fn from(e: WasmError) -> Self {
64 NodeError::fatal(e.kind(), e.to_string())
65 }
66}