wick_component_wasm/
error.rs

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use thiserror::Error;
use wick_rpc::error::RpcError;

#[derive(Error, Debug)]
#[non_exhaustive]

pub enum WasmComponentError {
  #[error("Could not extract claims signature from WASM module : {0}")]
  ClaimsError(String),

  #[error("Could not validate claims : {0}")]
  ClaimsInvalid(String),

  #[error(transparent)]
  WasmRS(#[from] wasmrs::Error),

  #[error("Setup failed: {}", .0.msg)]
  Setup(wasmrs::PayloadError),

  #[error(transparent)]
  SetupSignature(wick_packet::Error),

  #[error("Setup failed, operation timed out.")]
  SetupTimeout,

  #[error(transparent)]
  IoError(#[from] std::io::Error),

  #[error(transparent)]
  Asset(#[from] wick_config::AssetError),

  #[error("JSON Serialization/Deserialization error : {0}")]
  JsonError(String),

  #[error("WebAssembly engine failed: {0}")]
  EngineFailure(String),

  #[error(transparent)]
  ContextInit(wasmrs_host::errors::Error),

  #[error("Could not extract claims from component. Is it a signed WebAssembly module?")]
  ClaimsExtraction,

  #[error("Operation '{0}' not found. Valid operations are: {}", .1.join(", "))]
  OperationNotFound(String, Vec<String>),

  #[error("Operation '__setup' not exported by the wasm module.")]
  SetupOperation,
}

impl From<serde_json::error::Error> for WasmComponentError {
  fn from(e: serde_json::error::Error) -> Self {
    WasmComponentError::JsonError(e.to_string())
  }
}

impl From<WasmComponentError> for Box<RpcError> {
  fn from(e: WasmComponentError) -> Self {
    Box::new(RpcError::Component(e.to_string()))
  }
}

#[derive(Error, Debug)]
#[non_exhaustive]
pub enum LinkError {
  #[error("{0}")]
  EntityFailure(String),
  #[error("Component '{0}' can't call a link to itself.")]
  Circular(String),
  #[error("{0}")]
  CallFailure(String),
}