Skip to content

Commit a603fc5

Browse files
authored
Add a way to display only the trap's reason (without the backtrace) (bytecodealliance#3033)
1 parent a3e08ee commit a603fc5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

crates/wasmtime/src/trap.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ impl Trap {
264264
}
265265
}
266266

267+
/// Displays the error reason for this trap.
268+
///
269+
/// In particular, it differs from this struct's `Display` by *only*
270+
/// showing the reason, and not the full backtrace. This is useful to
271+
/// customize the way the trap is reported, for instance to display a short
272+
/// message for user-facing errors.
273+
pub fn display_reason<'a>(&'a self) -> impl fmt::Display + 'a {
274+
&self.inner.reason
275+
}
276+
267277
/// Returns a list of function frames in WebAssembly code that led to this
268278
/// trap happening.
269279
pub fn trace(&self) -> &[FrameInfo] {

0 commit comments

Comments
 (0)