-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
throwOnError
to throw errors on non-zero exits (#34)
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 } } ```
- Loading branch information
Showing
4 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type {Result, Output} from './main.js'; | ||
|
||
export class NonZeroExitError extends Error { | ||
public readonly result: Result; | ||
public readonly output?: Output; | ||
|
||
public get exitCode(): number | undefined { | ||
if (this.result.exitCode !== null) { | ||
return this.result.exitCode; | ||
} | ||
return undefined; | ||
} | ||
|
||
public constructor(result: Result, output?: Output) { | ||
super(`Process exited with non-zero status (${result.exitCode})`); | ||
|
||
this.result = result; | ||
this.output = output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters