Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Don't panic on traps without a core dump (#15282)

Alex Crichton5d042ce1cacb
diff --git a/src/commands.rs b/src/commands.rs
index ed70d5f837..da2cacf94d 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -56,7 +56,7 @@ pub use self::wizer::*;
))]
fn write_core_dump(
store: &mut impl wasmtime::AsContextMut,
- err: &wasmtime::Error,
+ core_dump: &wasmtime::WasmCoreDump,
name: &str,
path: &str,
) -> wasmtime::Result<()> {
@@ -64,9 +64,6 @@ fn write_core_dump(
use std::io::Write;
use wasmtime::error::Context as _;
- let core_dump = err
- .downcast_ref::<wasmtime::WasmCoreDump>()
- .expect("should have been configured to capture core dumps");
let core_dump = core_dump.serialize(store, name);
let mut core_dump_file =
File::create(path).with_context(|| format!("failed to create file at `{path}`"))?;
diff --git a/src/commands/run.rs b/src/commands/run.rs
index 200a46b0c2..02ae2dcdd4 100644
--- a/src/commands/run.rs
+++ b/src/commands/run.rs
@@ -1116,14 +1116,15 @@ impl RunCommand {
Some(path) => path,
None => return err,
};
- if !err.is::<wasmtime::Trap>() {
+ let Some(core_dump) = err.downcast_ref::<wasmtime::WasmCoreDump>() else {
return err;
- }
+ };
let source_name = self.module_and_args[0]
.to_str()
.unwrap_or_else(|| "unknown");
- if let Err(coredump_err) = super::write_core_dump(store, &err, &source_name, coredump_path)
+ if let Err(coredump_err) =
+ super::write_core_dump(store, core_dump, &source_name, coredump_path)
{
eprintln!("warning: coredump failed to generate: {coredump_err}");
err
diff --git a/src/commands/serve.rs b/src/commands/serve.rs
index b2daf5f904..e9461267a9 100644
--- a/src/commands/serve.rs
+++ b/src/commands/serve.rs
@@ -1023,10 +1023,10 @@ fn write_serve_coredump(state: &HostWorkerState, store: &mut Store<Host>, error:
let Some(path) = &state.coredump else {
return;
};
- if error.downcast_ref::<wasmtime::WasmCoreDump>().is_none() {
+ let Some(core_dump) = error.downcast_ref::<wasmtime::WasmCoreDump>() else {
return;
- }
- match super::write_core_dump(store, error, &state.coredump_name, path) {
+ };
+ match super::write_core_dump(store, core_dump, &state.coredump_name, path) {
Ok(()) => eprintln!("core dumped at {path}"),
Err(coredump_err) => eprintln!("warning: coredump failed to generate: {coredump_err}"),
}