Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't error if guest calls proc_exit with exit code 0 #180

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/wasm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -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::<wasmtime::Trap>() {
Some(trap) => match trap.i32_exit_status() {
Some(0) => Ok(()),
_ => Err(guest_err),
},
None => Err(guest_err),
}
}

pub enum RunWasmResult<T, E> {
Ok(T),
WasmError(E),
Expand Down