1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/// A convenience wrapper of `Result` that relies on
/// [`wasmtime_provider::errors::Error`](crate::errors::Error)
/// to hold errors
pub(crate) type Result<T> = std::result::Result<T, Error>;

/// This crate's Error type
#[derive(thiserror::Error, Debug)]
pub enum Error {
  /// Wasmtime initialization failed
  #[error("Initialization failed: {0}")]
  InitializationFailed(Box<dyn std::error::Error + Send + Sync>),

  /// Wasmtime initialization failed
  #[error("Initialization failed: {0} init interrupted, execution deadline exceeded")]
  InitializationFailedTimeout(String),

  /// The guest call function was not exported by the guest.
  #[error("Guest call function (__guest_call) not exported by wasm module.")]
  GuestCallNotFound,

  /// Error originating when wasi feature is disabled, but the user provides wasi related params
  #[error("WASI related parameter provided, but wasi feature is disabled")]
  WasiDisabled,

  /// Generic error
  // wasmtime uses `anyhow::Error` inside of its public API
  #[error(transparent)]
  Generic(#[from] anyhow::Error),
}

impl From<Error> for wapc::errors::Error {
  fn from(e: Error) -> Self {
    wapc::errors::Error::ProviderFailure(Box::new(e))
  }
}