wasmrs_wasmtime/
errors.rs1use wasi_common::StringArrayError;
2
3#[derive(thiserror::Error, Debug)]
5pub enum Error {
6 #[error("Initialization failed: {0}")]
8 Initialization(anyhow::Error),
9
10 #[error("Linker initialization failed: {0}")]
12 Linker(anyhow::Error),
13
14 #[error("Could not create WebAssembly function: {0}")]
16 Func(anyhow::Error),
17
18 #[error("Could not instantiate new WASM Module: {0}")]
20 Module(anyhow::Error),
21
22 #[error("Could not find module {0} in module cache")]
24 NotFound(String),
25
26 #[error(transparent)]
28 WasiError(#[from] wasi_common::Error),
29
30 #[error(transparent)]
32 WasiStringArray(#[from] StringArrayError),
33
34 #[error(transparent)]
36 IO(#[from] std::io::Error),
37
38 #[error("Guest init function not exported by wasm module.")]
40 GuestInit,
41
42 #[error("Guest send function not exported by wasm module.")]
44 GuestSend,
45
46 #[error("Could not read guest memory")]
48 GuestMemory,
49
50 #[error("Must provide a module to the builder")]
52 NoModule,
53
54 #[error("Must provide either module bytes with ID to cache or a cached ID, not both")]
56 AmbiguousModule,
57}
58
59impl From<Error> for wasmrs::Error {
60 fn from(e: Error) -> Self {
61 let code = match e {
62 Error::GuestMemory => wasmrs::ErrorCode::Canceled,
63 Error::Initialization(_) => wasmrs::ErrorCode::ConnectionError,
64 Error::Func(_) => wasmrs::ErrorCode::ConnectionError,
65 Error::Linker(_) => wasmrs::ErrorCode::ConnectionError,
66 Error::Module(_) => wasmrs::ErrorCode::ConnectionError,
67 Error::WasiError(_) => wasmrs::ErrorCode::ConnectionError,
68 _ => wasmrs::ErrorCode::ApplicationError,
69 };
70 wasmrs::Error::RSocket(code.into())
71 }
72}