Skip to content

Commit 7f32fff

Browse files
committed
Handle WASI exit codes properly
It turns out a non-zero exit code is returned as part of the `anytime::Error<>`. I'm not really sure what the inner `Result<>` is for.
1 parent fb95ed9 commit 7f32fff

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/engine.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use wasmtime::{
1111
component::{Component, Linker},
1212
};
1313
use wasmtime_wasi::{
14-
DirPerms, FilePerms, IoView, ResourceTable, WasiCtx, WasiCtxBuilder, WasiView,
15-
bindings::Command, pipe::MemoryOutputPipe,
14+
bindings::Command, pipe::MemoryOutputPipe, DirPerms, FilePerms, I32Exit, IoView, ResourceTable, WasiCtx, WasiCtxBuilder, WasiView
1615
};
1716

1817
use crate::{
@@ -216,10 +215,22 @@ async fn run_linter_command(
216215

217216
info!("Starting call");
218217

219-
let program_result = command.wasi_cli_run().call_run(&mut store).await?;
218+
let run_result = command.wasi_cli_run().call_run(&mut store).await;
219+
220+
// The return type here is very weird.
221+
match run_result {
222+
Ok(res) => res.map_err(|_| anyhow!("Unknown error running linter"))?,
223+
Err(error) => {
224+
if let Some(exit) = error.downcast_ref::<I32Exit>() {
225+
info!("Call failed with exit code {:?}", exit.0);
226+
return Ok(false);
227+
}
228+
return Err(error);
229+
}
230+
};
220231

221232
info!("Call finished");
222233

223234
// TODO (2.0): Use WASI to check if files were modified.
224-
Ok(program_result.is_ok())
235+
Ok(true)
225236
}

0 commit comments

Comments
 (0)