Skip to content

Commit

Permalink
wrapper mode: better handling of wasm exit code
Browse files Browse the repository at this point in the history
Handle exit codes in a better way, this code was already in place for
the "native run" mode.

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
  • Loading branch information
flavio committed Apr 12, 2022
1 parent ebf5cb6 commit afb5ee4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ mod wasm_host;
use clap::Parser;
use cli::{NativeCommands, BINARY_NAME, KREW_WASM_VERBOSE_ENV};

use errors::KrewWapcError;

use pull::ALL_MODULES_STORE_ROOT;

lazy_static! {
Expand Down Expand Up @@ -71,7 +73,19 @@ async fn main() {
let wasm_module_path = ALL_MODULES_STORE_ROOT.join(wasm_module_name);
if wasm_module_path.exists() {
let wasi_args = wasm_host::WasiArgs::Inherit;
wasm_host::run_plugin(wasm_module_path, &wasi_args).expect("error running wasm plugin");
match wasm_host::run_plugin(wasm_module_path, &wasi_args) {
Err(e) => match e {
KrewWapcError::PluginExitError { code } => {
println!();
process::exit(code)
}
_ => {
eprintln!("{:?}", e);
process::exit(1)
}
},
Ok(_) => process::exit(0),
}
} else {
eprintln!(
"Cannot find wasm plugin {} at {}. Use `krew-wasm pull` to pull it to the store from an OCI registry",
Expand Down

0 comments on commit afb5ee4

Please sign in to comment.