wasmer_artifact/error.rs
1//! The WebAssembly possible errors
2use std::io;
3use thiserror::Error;
4use wasmer_compiler::CompileError;
5use wasmer_types::ExternType;
6
7/// The Serialize error can occur when serializing a
8/// compiled Module into a binary.
9#[derive(Error, Debug)]
10pub enum SerializeError {
11 /// An IO error
12 #[error(transparent)]
13 Io(#[from] io::Error),
14 /// A generic serialization error
15 #[error("{0}")]
16 Generic(String),
17}
18
19/// The Deserialize error can occur when loading a
20/// compiled Module from a binary.
21#[derive(Error, Debug)]
22pub enum DeserializeError {
23 /// An IO error
24 #[error(transparent)]
25 Io(#[from] io::Error),
26 /// A generic deserialization error
27 #[error("{0}")]
28 Generic(String),
29 /// Incompatible serialized binary
30 #[error("incompatible binary: {0}")]
31 Incompatible(String),
32 /// The provided binary is corrupted
33 #[error("corrupted binary: {0}")]
34 CorruptedBinary(String),
35 /// The binary was valid, but we got an error when
36 /// trying to allocate the required resources.
37 #[error(transparent)]
38 Compiler(CompileError),
39}
40
41/// An ImportError.
42///
43/// Note: this error is not standard to WebAssembly, but it's
44/// useful to determine the import issue on the API side.
45#[derive(Error, Debug)]
46pub enum ImportError {
47 /// Incompatible Import Type.
48 /// This error occurs when the import types mismatch.
49 #[error("incompatible import type. Expected {0:?} but received {1:?}")]
50 IncompatibleType(ExternType, ExternType),
51
52 /// Unknown Import.
53 /// This error occurs when an import was expected but not provided.
54 #[error("unknown import. Expected {0:?}")]
55 UnknownImport(ExternType),
56}
57
58/// An error while preinstantiating a module.
59///
60#[derive(Error, Debug)]
61pub enum PreInstantiationError {
62 /// The module was compiled with a CPU feature that is not available on
63 /// the current host.
64 #[error("module compiled with CPU feature that is missing from host")]
65 CpuFeature(String),
66}