wasmer_compiler/engine/error.rs
1//! The WebAssembly possible errors
2use thiserror::Error;
3pub use wasmer_types::ImportError;
4#[cfg(not(target_arch = "wasm32"))]
5use wasmer_vm::Trap;
6
7/// The WebAssembly.LinkError object indicates an error during
8/// module instantiation (besides traps from the start function).
9///
10/// This is based on the [link error][link-error] API.
11///
12/// [link-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError
13#[derive(Error, Debug)]
14#[error("Link error: {0}")]
15pub enum LinkError {
16 /// An error occurred when checking the import types.
17 #[error("Error while importing {0:?}.{1:?}: {2}")]
18 Import(String, String, ImportError),
19
20 #[cfg(not(target_arch = "wasm32"))]
21 /// A trap ocurred during linking.
22 #[error("Trap occurred during linking: {0}")]
23 Trap(#[source] Trap),
24
25 /// Insufficient resources available for linking.
26 #[error("Insufficient resources: {0}")]
27 Resource(String),
28}
29
30/// An error while instantiating a module.
31///
32/// This is not a common WebAssembly error, however
33/// we need to differentiate from a `LinkError` (an error
34/// that happens while linking, on instantiation) and a
35/// Trap that occurs when calling the WebAssembly module
36/// start function.
37#[derive(Error, Debug)]
38pub enum InstantiationError {
39 /// A linking ocurred during instantiation.
40 #[error(transparent)]
41 Link(LinkError),
42
43 /// The module was compiled with a CPU feature that is not available on
44 /// the current host.
45 #[error("module compiled with CPU feature that is missing from host")]
46 CpuFeature(String),
47
48 /// A runtime error occured while invoking the start function
49 #[cfg(not(target_arch = "wasm32"))]
50 #[error(transparent)]
51 Start(Trap),
52}