Skip to content

feat: throw on non-zero exit#34

Merged
43081j merged 1 commit intomainfrom
nze
Aug 25, 2024
Merged

feat: throw on non-zero exit#34
43081j merged 1 commit intomainfrom
nze

Conversation

@43081j
Copy link
Copy Markdown
Member

@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
Copy Markdown
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
Copy Markdown
Member 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
  }
}
```
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