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