1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum WasmError {
8 #[error("failed to create WASM engine: {0}")]
10 EngineCreation(String),
11
12 #[error("failed to compile WASM module: {0}")]
14 Compilation(String),
15
16 #[error("failed to instantiate WASM module: {0}")]
18 Instantiation(String),
19
20 #[error("WASM execution trapped: {0}")]
22 Trap(String),
23
24 #[error("WASM execution timed out after {0}ms")]
26 Timeout(u64),
27
28 #[error("WASM memory limit exceeded: requested {requested} bytes, limit {limit} bytes")]
30 MemoryLimitExceeded { requested: usize, limit: usize },
31
32 #[error("missing required WASM export: {0}")]
34 MissingExport(String),
35
36 #[error("invalid export signature for '{name}': expected {expected}, got {actual}")]
38 InvalidExportSignature {
39 name: String,
40 expected: String,
41 actual: String,
42 },
43
44 #[error("plugin imports undeclared host function: {0}")]
46 UndeclaredImport(String),
47
48 #[error("unknown capability: {0}")]
50 UnknownCapability(String),
51
52 #[error("failed to parse plugin manifest: {0}")]
54 ManifestParse(String),
55
56 #[error("invalid plugin manifest: {0}")]
58 ManifestValidation(String),
59
60 #[error("failed to parse config schema: {0}")]
62 SchemaParse(String),
63
64 #[error("config validation failed: {0}")]
66 ConfigValidation(String),
67
68 #[error("plugin initialization failed: {0}")]
70 InitFailed(String),
71
72 #[error("invalid return code from plugin: {0}")]
74 InvalidReturnCode(i32),
75
76 #[error("serialization error: {0}")]
78 Serialization(String),
79
80 #[error("I/O error: {0}")]
82 Io(#[from] std::io::Error),
83}
84
85impl From<wasmtime::Error> for WasmError {
86 fn from(err: wasmtime::Error) -> Self {
87 WasmError::Compilation(err.to_string())
88 }
89}
90
91impl From<serde_json::Error> for WasmError {
92 fn from(err: serde_json::Error) -> Self {
93 WasmError::Serialization(err.to_string())
94 }
95}
96
97impl From<toml::de::Error> for WasmError {
98 fn from(err: toml::de::Error) -> Self {
99 WasmError::ManifestParse(err.to_string())
100 }
101}