Skip to content

Commit

Permalink
Merge #2026
Browse files Browse the repository at this point in the history
2026: expose trap error from RuntimeError r=syrusakbary a=ailisp

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description
<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

Internal of RuntimeError is private, user can know UserError via `downcast`, but user isn't able to tell the trap code if it's a `Trap`. This PR expose trap code via `RuntimeError#to_trap`. (And, if both downcast returns error and to_trap returns None, user will know it's a `RuntimeError::Generic`, which can be shown by `error.message()`, so there's no need to expose `RuntimeError::Generic` case)

# Review

- [] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Bo Yao <[email protected]>
  • Loading branch information
bors[bot] and ailisp authored Jan 15, 2021
2 parents 4edbde8 + 119ad09 commit 445269f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/engine/src/trap/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ impl RuntimeError {
}
}

/// Returns trap code, if it's a Trap
pub fn to_trap(self) -> Option<TrapCode> {
if let RuntimeErrorSource::Trap(trap_code) = self.inner.source {
Some(trap_code)
} else {
None
}
}

/// Returns true if the `RuntimeError` is the same as T
pub fn is<T: Error + 'static>(&self) -> bool {
match &self.inner.source {
Expand Down

0 comments on commit 445269f

Please sign in to comment.