-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3813 from wasmerio/better-errors
Better errors
- Loading branch information
Showing
35 changed files
with
697 additions
and
786 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
use crate::js::lib::std::string::String; | ||
pub use crate::js::trap::RuntimeError; | ||
#[cfg(feature = "std")] | ||
use thiserror::Error; | ||
use wasmer_types::ImportError; | ||
use crate::js::trap::Trap; | ||
use crate::RuntimeError; | ||
use wasm_bindgen::prelude::*; | ||
|
||
/// The WebAssembly.LinkError object indicates an error during | ||
/// module instantiation (besides traps from the start function). | ||
/// | ||
/// This is based on the [link error][link-error] API. | ||
/// | ||
/// [link-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError | ||
#[derive(Debug)] | ||
#[cfg_attr(feature = "std", derive(Error))] | ||
#[cfg_attr(feature = "std", error("Link error: {0}"))] | ||
pub enum LinkError { | ||
/// An error occurred when checking the import types. | ||
#[cfg_attr(feature = "std", error("Error while importing {0:?}.{1:?}: {2}"))] | ||
Import(String, String, ImportError), | ||
impl From<Trap> for RuntimeError { | ||
fn from(trap: Trap) -> Self { | ||
if trap.is::<RuntimeError>() { | ||
return trap.downcast::<RuntimeError>().unwrap(); | ||
} | ||
let wasm_trace = vec![]; | ||
let trap_code = None; | ||
// let (wasm_trace, trap_code) = wasmer_compiler::get_trace_and_trapcode(&trap); | ||
RuntimeError::new_from_source(trap, wasm_trace, trap_code) | ||
} | ||
} | ||
|
||
impl From<RuntimeError> for JsValue { | ||
fn from(_err: RuntimeError) -> Self { | ||
// err.inner.source.into() | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
/// A trap ocurred during linking. | ||
#[cfg_attr(feature = "std", error("RuntimeError occurred during linking: {0}"))] | ||
Trap(#[source] RuntimeError), | ||
/// Insufficient resources available for linking. | ||
#[cfg_attr(feature = "std", error("Insufficient resources: {0}"))] | ||
Resource(String), | ||
pub(crate) fn raise(error: Box<dyn std::error::Error + Send + Sync>) -> ! { | ||
let error = Trap::user(error); | ||
let js_error: JsValue = error.into(); | ||
wasm_bindgen::throw_val(js_error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.