diff --git a/crates/c-api/src/trap.rs b/crates/c-api/src/trap.rs index 213bb9740f..6f60709fe4 100644 --- a/crates/c-api/src/trap.rs +++ b/crates/c-api/src/trap.rs @@ -64,13 +64,7 @@ pub extern "C" fn wasm_trap_message(trap: &wasm_trap_t, out: &mut wasm_message_t #[no_mangle] pub extern "C" fn wasm_trap_origin(raw: &wasm_trap_t) -> Option> { - if raw - .trap - .trace() - .expect("backtraces are always enabled") - .len() - > 0 - { + if raw.trap.trace().unwrap_or(&[]).len() > 0 { Some(Box::new(wasm_frame_t { trap: raw.trap.clone(), idx: 0, @@ -84,11 +78,7 @@ pub extern "C" fn wasm_trap_origin(raw: &wasm_trap_t) -> Option &mut Self { self.wasm_backtrace = enable; #[cfg(compiler)] diff --git a/crates/wasmtime/src/trap.rs b/crates/wasmtime/src/trap.rs index 977e8bd050..85d61ee6f9 100644 --- a/crates/wasmtime/src/trap.rs +++ b/crates/wasmtime/src/trap.rs @@ -295,6 +295,14 @@ impl Trap { /// Returns a list of function frames in WebAssembly code that led to this /// trap happening. + /// + /// This function return an `Option` of a list of frames to indicate that + /// wasm frames are not always available. Frames will never be available if + /// backtraces are disabled via + /// [`Config::wasm_backtrace`](crate::Config::wasm_backtrace). Frames will + /// also not be available for freshly-created traps. WebAssembly frames are + /// currently only captured when the trap reaches wasm itself to get raised + /// across a wasm boundary. pub fn trace(&self) -> Option<&[FrameInfo]> { self.inner .backtrace