-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exit with a more severe error code if the program traps. #1274
Conversation
src/commands/run.rs
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut err = Some(&e);
while let Some(source) = err {
if source.is::<Trap>() { ... }
err = source.source();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.