wasmrs_testhost/
errors.rs

1/// This crate's Error type
2#[derive(thiserror::Error, Debug)]
3pub enum Error {
4  /// WASMTime initialization failed
5  #[error("Initialization failed: {0}")]
6  InitializationFailed(Box<dyn std::error::Error + Send + Sync>),
7
8  /// WASMTime initialization failed
9  #[error("Initialization failed: {0}")]
10  Initialization(anyhow::Error),
11
12  /// WASMTime Linker initialization failed
13  #[error("Linker initialization failed: {0}")]
14  Linker(anyhow::Error),
15
16  /// Setting up linked functions failed.
17  #[error("Could not create WebAssembly function: {0}")]
18  Func(anyhow::Error),
19
20  /// WASMTime module instantiation failed
21  #[error("Could not instantiate new WASM Module: {0}")]
22  Module(anyhow::Error),
23
24  /// Error originating from [wasi_common]
25  #[error("{0}")]
26  WasiError(#[from] wasi_common::Error),
27
28  /// Thrown if the guest's send function is not exported.
29  #[error("Guest init function not exported by wasm module.")]
30  GuestInit,
31
32  /// Thrown if the guest's send function is not exported.
33  #[error("Guest send function not exported by wasm module.")]
34  GuestSend,
35
36  /// Thrown if the host has a problem reading the guest's memory.
37  #[error("Could not read guest memory")]
38  GuestMemory,
39}
40
41impl From<Error> for wasmrs::Error {
42  fn from(e: Error) -> Self {
43    let code = match e {
44      Error::InitializationFailed(_) => wasmrs::ErrorCode::ConnectionError,
45      Error::Initialization(_) => wasmrs::ErrorCode::ConnectionError,
46      Error::Func(_) => wasmrs::ErrorCode::ConnectionError,
47      Error::Linker(_) => wasmrs::ErrorCode::ConnectionError,
48      Error::Module(_) => wasmrs::ErrorCode::ConnectionError,
49      Error::WasiError(_) => wasmrs::ErrorCode::ConnectionError,
50      Error::GuestInit => wasmrs::ErrorCode::ApplicationError,
51      Error::GuestSend => wasmrs::ErrorCode::ApplicationError,
52      Error::GuestMemory => wasmrs::ErrorCode::Canceled,
53    };
54    wasmrs::Error::RSocket(code.into())
55  }
56}