[wasm] Add the ability to provide a user-defined error;

This commit is contained in:
Benjamin Bouvier
2019-04-29 11:34:45 +02:00
parent 02e114cf3d
commit 3ce5d2057d
2 changed files with 14 additions and 2 deletions

View File

@@ -27,7 +27,7 @@ target-lexicon = "0.4.0"
[features] [features]
default = ["std"] default = ["std"]
std = ["cranelift-codegen/std", "cranelift-frontend/std", "wasmparser/std"] std = ["cranelift-codegen/std", "cranelift-frontend/std", "wasmparser/std", "failure/std"]
core = ["hashmap_core", "cranelift-codegen/core", "cranelift-frontend/core", "wasmparser/core"] core = ["hashmap_core", "cranelift-codegen/core", "cranelift-frontend/core", "wasmparser/core"]
[badges] [badges]

View File

@@ -39,7 +39,7 @@ pub enum GlobalVariable {
/// ///
/// When a WebAssembly function can't be translated, one of these error codes will be returned /// When a WebAssembly function can't be translated, one of these error codes will be returned
/// to describe the failure. /// to describe the failure.
#[derive(Fail, Debug, PartialEq, Eq)] #[derive(Fail, Debug)]
pub enum WasmError { pub enum WasmError {
/// The input WebAssembly code is invalid. /// The input WebAssembly code is invalid.
/// ///
@@ -67,6 +67,18 @@ pub enum WasmError {
/// [limits]: https://cranelift.readthedocs.io/en/latest/ir.html#implementation-limits /// [limits]: https://cranelift.readthedocs.io/en/latest/ir.html#implementation-limits
#[fail(display = "Implementation limit exceeded")] #[fail(display = "Implementation limit exceeded")]
ImplLimitExceeded, ImplLimitExceeded,
/// Any user-defined error. Requires an std build, where failure::Error is defined.
#[cfg(feature = "std")]
#[fail(display = "User error: {}", _0)]
User(failure::Error),
}
#[cfg(feature = "std")]
impl From<failure::Error> for WasmError {
fn from(err: failure::Error) -> Self {
WasmError::User(err)
}
} }
impl From<BinaryReaderError> for WasmError { impl From<BinaryReaderError> for WasmError {