diff --git a/CHANGELOG.md b/CHANGELOG.md index 722f04d4401..774342db242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ## **[Unreleased]** ### Added +- [#2026](https://github.com/wasmerio/wasmer/pull/2010) Expose trap code of a `RuntimeError`, if it's a `Trap`. ### Changed diff --git a/lib/engine/src/trap/error.rs b/lib/engine/src/trap/error.rs index c7811aa082a..36cdb7e49bc 100644 --- a/lib/engine/src/trap/error.rs +++ b/lib/engine/src/trap/error.rs @@ -207,6 +207,15 @@ impl RuntimeError { } } + /// Returns trap code, if it's a Trap + pub fn to_trap(self) -> Option { + 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(&self) -> bool { match &self.inner.source {