From 47cb39837c0e2d72c342fcf0a8a9dcfb415ab89b Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Fri, 25 Jun 2021 11:35:18 +0200 Subject: [PATCH] Add a way to display only the trap's reason (without the backtrace) --- crates/wasmtime/src/trap.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/wasmtime/src/trap.rs b/crates/wasmtime/src/trap.rs index 602d73eb83b9..790f592a7815 100644 --- a/crates/wasmtime/src/trap.rs +++ b/crates/wasmtime/src/trap.rs @@ -264,6 +264,16 @@ impl Trap { } } + /// Displays the error reason for this trap. + /// + /// In particular, it differs from this struct's `Display` by *only* + /// showing the reason, and not the full backtrace. This is useful to + /// customize the way the trap is reported, for instance to display a short + /// message for user-facing errors. + pub fn display_reason<'a>(&'a self) -> impl fmt::Display + 'a { + &self.inner.reason + } + /// Returns a list of function frames in WebAssembly code that led to this /// trap happening. pub fn trace(&self) -> &[FrameInfo] {