-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a breaking change which causes the process to throw when 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'); } 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
3 changed files
with
38 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type {Result} from './main.js'; | ||
|
||
export class NonZeroExitError extends Error { | ||
public readonly result: Result; | ||
|
||
public get exitCode(): number | undefined { | ||
if (this.result.exitCode !== null) { | ||
return this.result.exitCode; | ||
} | ||
return undefined; | ||
} | ||
|
||
public constructor(result: Result) { | ||
super(`Process exited with non-zero status (${result.exitCode})`); | ||
|
||
this.result = result; | ||
} | ||
} |
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