Skip to content
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

Merged
merged 8 commits into from
Mar 11, 2020
Merged

Conversation

sunfishcode
Copy link
Member

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.

// than a simple failure.
if let Some(source) = e.source() {
if let Some(source) = source.source() {
if source.is::<Trap>() {
Copy link
Member

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?

Copy link
Member

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();
}

Copy link
Member Author

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.

Copy link
Member

@fitzgen fitzgen left a 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

src/commands/run.rs Outdated Show resolved Hide resolved
Copy link
Member

@alexcrichton alexcrichton left a 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?

@sunfishcode
Copy link
Member Author

Test added!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants