marine_wasm_backend_traits/
errors.rs1use crate::WType;
18
19use thiserror::Error;
20
21pub type WasmBackendResult<T> = Result<T, WasmBackendError>;
22pub type ResolveResult<T> = Result<T, ResolveError>;
23pub type RuntimeResult<T> = Result<T, RuntimeError>;
24pub type ModuleCreationResult<T> = Result<T, ModuleCreationError>;
25pub type InstantiationResult<T> = Result<T, InstantiationError>;
26pub type WasiResult<T> = Result<T, WasiError>;
27
28#[derive(Debug, Error)]
40pub enum WasmBackendError {
41 #[error(transparent)]
42 ResolveError(#[from] ResolveError),
43
44 #[error(transparent)]
45 RuntimeError(#[from] RuntimeError),
46
47 #[error(transparent)]
48 ModuleCreationError(#[from] ModuleCreationError),
49
50 #[error(transparent)]
51 ImportError(#[from] ImportError),
52
53 #[error(transparent)]
54 InstantiationError(#[from] InstantiationError),
55
56 #[error(transparent)]
57 InitializationError(anyhow::Error),
58}
59
60#[derive(Debug, Error)]
61pub enum ResolveError {
62 #[error("export not found: {0}")]
63 ExportNotFound(String),
64
65 #[error("export type mismatch: expected {expected}, found {actual}")]
66 ExportTypeMismatch {
67 expected: &'static str,
68 actual: &'static str,
69 },
70
71 #[error(transparent)]
72 Other(#[from] anyhow::Error),
73}
74
75#[derive(Debug, Error)]
76pub enum RuntimeError {
77 #[error("Unsupported type encountered: {0}")]
78 UnsupportedType(WType),
79
80 #[error("Trap occurred: {0}")]
81 Trap(anyhow::Error),
82
83 #[error(transparent)]
84 UserError(#[from] UserError),
85
86 #[error("A function returned invalid number of results: expected {expected}, got {actual}")]
87 IncorrectResultsNumber { expected: usize, actual: usize },
88
89 #[error("Unrecognized error: {0}")]
90 Other(anyhow::Error),
91}
92
93#[derive(Debug, Error)]
94pub enum ModuleCreationError {
95 #[error(transparent)]
96 FailedToCompileWasm(anyhow::Error),
97
98 #[error("{0}")]
99 FailedToExtractCustomSections(String), #[error(transparent)]
102 Other(anyhow::Error),
103}
104
105#[derive(Debug, Error)]
106pub enum ImportError {
107 #[error("Duplicate import")]
108 DuplicateImport(String, String),
109
110 #[error(transparent)]
111 Other(#[from] anyhow::Error),
112}
113
114#[derive(Debug, Error)]
115pub enum InstantiationError {
116 #[error(transparent)]
117 RuntimeError(RuntimeError),
118
119 #[error(transparent)]
120 Other(#[from] anyhow::Error),
121}
122
123#[derive(Debug, Error)]
124pub enum WasiError {
125 #[error(transparent)]
126 IOError(#[from] std::io::Error),
127
128 #[error(transparent)]
129 EngineWasiError(#[from] anyhow::Error),
130
131 #[error("Cumulative size of args array exceeds 2^32")]
132 TooLargeArgsArray,
133
134 #[error("Cumulative size of envs array exceeds 2^32")]
135 TooLargeEnvsArray,
136}
137
138#[derive(Debug, Error)]
139pub enum UserError {
140 #[error(transparent)]
141 Recoverable(anyhow::Error),
142
143 #[error(transparent)]
144 Unrecoverable(anyhow::Error),
145}