diff --git a/src/wasm_runner.rs b/src/wasm_runner.rs index e2de16d..cc2ea85 100644 --- a/src/wasm_runner.rs +++ b/src/wasm_runner.rs @@ -116,7 +116,8 @@ pub fn run_prepared_wasm_instance( anyhow::anyhow!("No such function '{}' in {}", entrypoint, wasm_module_name) })?; tracing::trace!("Calling Wasm entry point"); - start.call(&mut store, &[], &mut vec![])?; + start.call(&mut store, &[], &mut vec![]) + .or_else(ignore_successful_proc_exit_trap)?; tracing::trace!("Module execution complete"); Ok(()) } @@ -135,6 +136,16 @@ pub fn run_prepared_wasm_instance_if_present( } } +fn ignore_successful_proc_exit_trap(guest_err: anyhow::Error) -> anyhow::Result<()> { + match guest_err.root_cause().downcast_ref::() { + Some(trap) => match trap.i32_exit_status() { + Some(0) => Ok(()), + _ => Err(guest_err), + }, + None => Err(guest_err), + } +} + pub enum RunWasmResult { Ok(T), WasmError(E),