Skip to content
This repository was archived by the owner on Oct 26, 2021. It is now read-only.

Commit bcfcfa7

Browse files
committed
wasmldr: exit with a useful exit code
Currently, when wasmldr exits due to ExportNotFound, it returns an exit code of... 101. Why 101? Great question! I have absolutely no idea. In order to make things a bit more sensible, I've defined different exit codes for different errors. They roughly match FreeBSD's "preferable" exit codes, as defined in `sysexits.h` - see [sysexits(3)] for more info. [sysexits(3)]: https://www.freebsd.org/cgi/man.cgi?sektion=3&query=sysexits Signed-off-by: Will Woods <[email protected]>
1 parent d3135cc commit bcfcfa7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

internal/wasmldr/src/main.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,29 @@ fn main() {
6666

6767
info!("running workload");
6868
// TODO: pass opts.wasm_features
69-
let result = workload::run(bytes, opts.args, opts.envs).expect("Failed to run workload");
69+
let result = workload::run(bytes, opts.args, opts.envs);
7070
info!("got result: {:#?}", result);
71-
// TODO: exit with the resulting code, if the result is a return code
71+
7272
// FUTURE: produce attestation report here
73+
// TODO: print the returned value(s) in some format (json?)
74+
75+
// Choose an appropriate exit code
76+
// TODO: exit with the resulting code, if the result is a return code
77+
std::process::exit(match result {
78+
// Success -> EX_OK
79+
Ok(_) => 0,
80+
81+
// wasmtime/WASI/module setup errors -> EX_DATAERR
82+
Err(workload::Error::ConfigurationError) => 65,
83+
Err(workload::Error::StringTableError) => 65,
84+
Err(workload::Error::InstantiationFailed) => 65,
85+
Err(workload::Error::ExportNotFound) => 65,
86+
Err(workload::Error::CallFailed) => 65,
87+
88+
// Internal WASI errors -> EX_SOFTWARE
89+
Err(workload::Error::WASIError(_)) => 70,
90+
91+
// General IO errors -> EX_IOERR
92+
Err(workload::Error::IoError(_)) => 74,
93+
});
7394
}

0 commit comments

Comments
 (0)