feat: treat 0 exit code as success
use super::{Completed, Connected, Loader};
-use anyhow::Result;
+use anyhow::{bail, Context, Result};
+use wasmtime::Trap;
impl Loader<Connected> {
- pub fn next(mut self) -> Result<Loader<Completed>> {
- let func = self.0.linker.get_default(&mut self.0.wstore, "")?;
+ pub fn next(self) -> Result<Loader<Completed>> {
+ let Self(Connected { mut wstore, linker }) = self;
- let mut values = vec![wasmtime::Val::null(); func.ty(&self.0.wstore).results().len()];
- func.call(self.0.wstore, Default::default(), &mut values)?;
+ let func = linker
+ .get_default(&mut wstore, "")
+ .context("failed to get default function")?;
+ let mut values = vec![wasmtime::Val::null(); func.ty(&wstore).results().len()];
+ if let Err(e) = func.call(wstore, Default::default(), &mut values) {
+ match e.downcast_ref::<Trap>().map(Trap::i32_exit_status) {
+ Some(Some(0)) => {} // function exited with a code of 0, treat as success
+ _ => bail!(e.context("failed to execute default function")),
+ }
+ };
Ok(Loader(Completed { values }))
}
}
