use crate::value::ValType;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
RuntimeInit,
ModuleLoad(String),
Instantiate(String),
FuncNotFound(String),
Trap(String),
SignatureMismatch {
expected: usize,
provided: usize,
},
GlobalNotFound(String),
GlobalImmutable,
TypeMismatch {
expected: ValType,
provided: ValType,
},
UnsupportedType,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::RuntimeInit => write!(f, "failed to initialize the WAMR runtime"),
Error::ModuleLoad(msg) => write!(f, "failed to load Wasm module: {msg}"),
Error::Instantiate(msg) => write!(f, "failed to instantiate Wasm module: {msg}"),
Error::FuncNotFound(name) => write!(f, "exported function not found: {name}"),
Error::Trap(msg) => write!(f, "Wasm trap: {msg}"),
Error::SignatureMismatch { expected, provided } => {
write!(
f,
"signature mismatch: expected {expected}, provided {provided}"
)
}
Error::GlobalNotFound(name) => write!(f, "exported global not found: {name}"),
Error::GlobalImmutable => write!(f, "cannot set an immutable global"),
Error::TypeMismatch { expected, provided } => {
write!(f, "type mismatch: expected {expected}, provided {provided}")
}
Error::UnsupportedType => {
write!(f, "unsupported Wasm value type (only i32/i64/f32/f64)")
}
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;