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

feat: throw on non-zero exit #34

Merged
merged 1 commit into from
Aug 25, 2024
Merged

feat: throw on non-zero exit #34

merged 1 commit into from
Aug 25, 2024

Conversation

43081j
Copy link
Collaborator

@43081j 43081j commented Aug 22, 2024

Introduces a new throwOnError option which will cause tinyexec to
throw any time a non-zero exit code is encountered.

If the exit code is null, we will not throw since it means something
went very wrong anyway (the process is still running and shouldn't be,
since we saw the close event by then).

If the exit code is greater than 0, we will throw a
NonZeroExitError which has an exitCode property.

For example:

try {
  await x('foo', [], {throwOnError: true});
} catch (err) {
  if (err instanceof NonZeroExitCode) {
    err.exitCode; // the exit code
    err.result; // the tinyexec process
    err.result.killed; // getters on tinyexec process
  }
}

cc @benmccann

Copy link
Contributor

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! It'd probably be good to add some docs

@43081j 43081j force-pushed the nze branch 2 times, most recently from d1cc244 to 703c3ce Compare August 25, 2024 16:56
@43081j
Copy link
Collaborator Author

43081j commented Aug 25, 2024

have updated to be a throwOnError option rather than a breaking change

Introduces a new `throwOnError` option which will cause tinyexec to
throw any time a non-zero exit code is encountered.

If the exit code is `null`, we will not throw since it means something
went very wrong anyway (the process is still running and shouldn't be,
since we saw the `close` event by then).

If the exit code is greater than `0`, we will throw a
`NonZeroExitError` which has an `exitCode` property.

For example:

```ts
try {
  await x('foo', [], {throwOnError: true});
} catch (err) {
  if (err instanceof NonZeroExitCode) {
    err.exitCode; // the exit code
    err.result; // the tinyexec process
    err.result.killed; // getters on tinyexec process
  }
}
```
@43081j 43081j merged commit f11e42b into main Aug 25, 2024
7 checks passed
@43081j 43081j deleted the nze branch August 25, 2024 17:49
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.

2 participants