From baabd40b94fcfa733b942f42b49caace7643bf45 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 28 Jun 2022 12:20:25 -0500 Subject: [PATCH] Improve error message for failed function compiles (#4340) * Improve error message for failed function compiles Add in the wasm function index, the name if specified, and the function offset in the original file to assist in debugging failed function compiles. * Review commments --- crates/wasmtime/src/module.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/wasmtime/src/module.rs b/crates/wasmtime/src/module.rs index 1d23d8b8d0..5524ebb731 100644 --- a/crates/wasmtime/src/module.rs +++ b/crates/wasmtime/src/module.rs @@ -374,9 +374,21 @@ impl Module { let functions = functions.into_iter().collect::>(); let funcs = engine .run_maybe_parallel(functions, |(index, func)| { + let offset = func.body.range().start; engine .compiler() .compile_function(&translation, index, func, tunables, types) + .with_context(|| { + let index = translation.module.func_index(index); + let name = match translation.debuginfo.name_section.func_names.get(&index) { + Some(name) => format!(" (`{}`)", name), + None => String::new(), + }; + let index = index.as_u32(); + format!( + "failed to compile wasm function {index}{name} at offset {offset:#x}" + ) + }) })? .into_iter() .collect();