Exit with a more severe error code if the program traps.#1274
Exit with a more severe error code if the program traps.#1274sunfishcode merged 8 commits intomasterfrom
Conversation
| // than a simple failure. | ||
| if let Some(source) = e.source() { | ||
| if let Some(source) = source.source() { | ||
| if source.is::<Trap>() { |
There was a problem hiding this comment.
Rather than hard-coding "check for a trap two error sources above this error in the chain" I think it would make sense to loop over the whole chain and check for if any of them is a trap. Does that make sense?
There was a problem hiding this comment.
let mut err = Some(&e);
while let Some(source) = err {
if source.is::<Trap>() { ... }
err = source.source();
}There was a problem hiding this comment.
Makes sense to me! I've now added a patch to do that. I just had to make a slight tweek, since e here is an anyhow::Error, so we have to start with the first source() rather than starting with e.
fitzgen
left a comment
There was a problem hiding this comment.
Looks great! FWIW, I forgot that anyhow has an iterator to do this already, so we could skip the while let if we want: https://docs.rs/anyhow/1.0.26/anyhow/struct.Chain.html
alexcrichton
left a comment
There was a problem hiding this comment.
Mind adding a test for this as well?
|
Test added! |
Previously, the wasmtime CLI would return with a regular failure error code, such as 1 on Unix. However, a program trap indicates a bug in the program, which can be useful to distinguish from a simple error status. Check for the trap case, and return an appropriate OS-specific exit status.
Previously, the wasmtime CLI would return with a regular failure
error code, eg. 1 on Unix. However, a program trap indicates a bug in
the program, which can be useful to distinguish from a simple error
status. Check for the trap case, and return an appropriate OS-specific
exit status.