mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
impl error trait for ResolveError (#179)
This commit is contained in:
parent
5948fa1d20
commit
24d028e2a2
@ -1,6 +1,7 @@
|
|||||||
use crate::types::{
|
use crate::types::{
|
||||||
FuncSig, GlobalDescriptor, MemoryDescriptor, MemoryIndex, TableDescriptor, TableIndex, Type,
|
FuncSig, GlobalDescriptor, MemoryDescriptor, MemoryIndex, TableDescriptor, TableIndex, Type,
|
||||||
};
|
};
|
||||||
|
use core::borrow::Borrow;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@ -135,6 +136,31 @@ impl PartialEq for ResolveError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ResolveError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
ResolveError::ExportNotFound { name } => write!(f, "Export not found: {}", name),
|
||||||
|
ResolveError::ExportWrongType { name } => write!(f, "Export wrong type: {}", name),
|
||||||
|
ResolveError::Signature { expected, found } => {
|
||||||
|
let found = found
|
||||||
|
.as_slice()
|
||||||
|
.iter()
|
||||||
|
.map(|p| p.to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ");
|
||||||
|
let expected: &FuncSig = expected.borrow();
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"Parameters of type [{}] did not match signature {}",
|
||||||
|
found, expected
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for ResolveError {}
|
||||||
|
|
||||||
/// This error type is produced by calling a wasm function
|
/// This error type is produced by calling a wasm function
|
||||||
/// exported from a module.
|
/// exported from a module.
|
||||||
///
|
///
|
||||||
|
@ -15,6 +15,12 @@ pub enum Type {
|
|||||||
F64,
|
F64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Type {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
write!(f, "{:?}", self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a WebAssembly value.
|
/// Represents a WebAssembly value.
|
||||||
///
|
///
|
||||||
/// As the number of types in WebAssembly expand,
|
/// As the number of types in WebAssembly expand,
|
||||||
@ -292,6 +298,24 @@ impl FuncSig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for FuncSig {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
let params = self
|
||||||
|
.params
|
||||||
|
.iter()
|
||||||
|
.map(|p| p.to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ");
|
||||||
|
let returns = self
|
||||||
|
.returns
|
||||||
|
.iter()
|
||||||
|
.map(|p| p.to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ");
|
||||||
|
write!(f, "[{}] -> [{}]", params, returns)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait LocalImport {
|
pub trait LocalImport {
|
||||||
type Local: TypedIndex;
|
type Local: TypedIndex;
|
||||||
type Import: TypedIndex;
|
type Import: TypedIndex;
|
||||||
|
Loading…
Reference in New Issue
Block a user