Skip to content

Commit d72587f

Browse files
committed
Handle exit(0) correctly
WASI treats returning from main and `exit(..)` differently, and `exit(0)` actually results in `Err(I32Exit(0))` which is surprising!
1 parent e8b03ed commit d72587f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/engine.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,20 @@ async fn run_linter_command(
217217

218218
let run_result = command.wasi_cli_run().call_run(&mut store).await;
219219

220-
// The return type here is very weird.
220+
// The return type here is very weird. See
221+
// https://github.com/bytecodealliance/wasmtime/issues/10767
221222
match run_result {
222223
Ok(res) => res.map_err(|_| anyhow!("Unknown error running linter"))?,
223224
Err(error) => {
224225
if let Some(exit) = error.downcast_ref::<I32Exit>() {
225-
info!("Call failed with exit code {:?}", exit.0);
226-
return Ok(false);
226+
// Err(I32Exit(0)) is actually success.
227+
if exit.0 != 0 {
228+
info!("Call failed with exit code {:?}", exit.0);
229+
return Ok(false);
230+
}
231+
} else {
232+
return Err(error);
227233
}
228-
return Err(error);
229234
}
230235
};
231236

0 commit comments

Comments
 (0)