Misc fixes

This commit is contained in:
Lachlan Sneff
2019-04-01 17:50:53 -07:00
parent 8bab9f1bea
commit 287c81d7a5
4 changed files with 37 additions and 15 deletions

View File

@ -119,7 +119,6 @@ impl std::error::Error for LinkError {}
/// The main way to do this is `Instance.call`.
///
/// Comparing two `RuntimeError`s always evaluates to false.
#[derive(Debug)]
pub enum RuntimeError {
Trap { msg: Box<str> },
Exception { data: Box<[Value]> },
@ -141,11 +140,27 @@ impl std::fmt::Display for RuntimeError {
RuntimeError::Exception { ref data } => {
write!(f, "Uncaught WebAssembly exception: {:?}", data)
}
RuntimeError::Panic { data: _ } => write!(f, "User-defined \"panic\""),
RuntimeError::Panic { data } => {
let msg = if let Some(s) = data.downcast_ref::<String>() {
s
} else if let Some(s) = data.downcast_ref::<&str>() {
s
} else {
"user-defined, opaque"
};
write!(f, "{}", msg)
}
}
}
}
impl std::fmt::Debug for RuntimeError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self)
}
}
impl std::error::Error for RuntimeError {}
/// This error type is produced by resolving a wasm function
@ -197,7 +212,6 @@ impl std::error::Error for ResolveError {}
/// be the `CallError::Runtime(RuntimeError)` variant.
///
/// Comparing two `CallError`s always evaluates to false.
#[derive(Debug)]
pub enum CallError {
Resolve(ResolveError),
Runtime(RuntimeError),
@ -218,6 +232,15 @@ impl std::fmt::Display for CallError {
}
}
impl std::fmt::Debug for CallError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
CallError::Resolve(resolve_err) => write!(f, "ResolveError: {:?}", resolve_err),
CallError::Runtime(runtime_err) => write!(f, "RuntimeError: {:?}", runtime_err),
}
}
}
impl std::error::Error for CallError {}
/// This error type is produced when creating something,