Improve documentation of `error.*` fields (#1006)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent f8d4e08 · Browse files · 6 files·+85 added−75 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+85 added−75 removed
- other:+85 added−75 removed
Provenance
- Commit
4ee0dec- Tree
7eba7df- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
f8d4e08
6 files changed+85 added−75 removed
modified:docs/api.md+67 added-63 removed
191 unmodified lines192 `signal`: `string | number`\193 `error`: `Error`\194 _Returns_: `boolean`195 196-Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the [`killSignal`](#optionskillsignal) option. `killSignal` defaults to `SIGTERM`, which [terminates](#resultisterminated) the subprocess.196+Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the [`killSignal`](#optionskillsignal) option. `killSignal` defaults to `SIGTERM`, which [terminates](#erroristerminated) the subprocess.197 198 This returns `false` when the signal could not be sent, for example when the subprocess has already exited.199 200 When an error is passed as argument, it is set to the subprocess' [`error.cause`](#errorcause). The subprocess is then terminated with the default signal. This does not emit the [`error` event](https://nodejs.org/api/child_process.html#event-error).167 unmodified lines368 ## Result369 370 Type: `object`371 372-[Result](execution.md#result) of a subprocess execution.372+[Result](execution.md#result) of a subprocess successful execution.373 374 When the subprocess [fails](errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.375 376 ### result.stdout93 unmodified lines470 Type: `boolean`471 472 Whether the subprocess failed to run.473 474+When this is `true`, the result is an [`ExecaError`](#execaerror) instance with additional error-related properties.475+476 [More info.](errors.md#subprocess-failure)477 476-### result.timedOut478+## ExecaError479+## ExecaSyncError480 481+Type: `Error`482+483+Result of a subprocess [failed execution](errors.md#subprocess-failure).484+485+This error is thrown as an exception. If the [`reject`](#optionsreject) option is false, it is returned instead.486+487+This has the same shape as [successful results](#result), with the following additional properties.488+489+[More info.](errors.md)490+491+### error.message492+493+Type: `string`494+495+Error message when the subprocess [failed](errors.md#subprocess-failure) to run.496+497+[More info.](errors.md#error-message)498+499+### error.shortMessage500+501+Type: `string`502+503+This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).504+505+[More info.](errors.md#error-message)506+507+### error.originalMessage508+509+Type: `string | undefined`510+511+Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.512+513+[More info.](errors.md#error-message)514+515+### error.cause516+517+Type: `unknown | undefined`518+519+Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).520+521+This is usually an `Error` instance.522+523+[More info.](termination.md#error-message-and-stack-trace)524+525+### error.code526+527+Type: `string | undefined`528+529+Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.530+531+### error.timedOut532+533 Type: `boolean`534 535 Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.536 537 [More info.](termination.md#timeout)538 484-### result.isCanceled539+### error.isCanceled540 541 Type: `boolean`542 543 Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.544 545 [More info.](termination.md#canceling)546 492-### result.isMaxBuffer547+### error.isMaxBuffer548 549 Type: `boolean`550 551 Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.552 553 [More info.](output.md#big-output)554 500-### result.isTerminated555+### error.isTerminated556 557 Type: `boolean`558 559 Whether the subprocess was terminated by a [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) sent by either:1 unmodified line561 - [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).562 563 [More info.](termination.md#signal-name-and-description)564 510-### result.exitCode565+### error.exitCode566 567 Type: `number | undefined`568 569 The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.570 516-This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#resultsignal).571+This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#errorsignal).572 573 [More info.](errors.md#exit-code)574 520-### result.signal575+### error.signal576 577 Type: `string | undefined`578 579 The name of the [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) that terminated the subprocess, sent by either:3 unmodified lines583 If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.584 585 [More info.](termination.md#signal-name-and-description)586 532-### result.signalDescription587+### error.signalDescription588 589 Type: `string | undefined`590 591 A human-friendly description of the [signal](termination.md#signal-termination) that was used to terminate the subprocess.1 unmodified line593 If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.594 595 [More info.](termination.md#signal-name-and-description)596 542-## ExecaError543-## ExecaSyncError544-545-Type: `Error`546-547-Exception thrown when the subprocess [fails](errors.md#subprocess-failure).548-549-This has the same shape as [successful results](#result), with the following additional properties.550-551-[More info.](errors.md)552-553-### error.message554-555-Type: `string`556-557-Error message when the subprocess [failed](errors.md#subprocess-failure) to run.558-559-[More info.](errors.md#error-message)560-561-### error.shortMessage562-563-Type: `string`564-565-This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).566-567-[More info.](errors.md#error-message)568-569-### error.originalMessage570-571-Type: `string | undefined`572-573-Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.574-575-[More info.](errors.md#error-message)576-577-### error.cause578-579-Type: `unknown | undefined`580-581-Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).582-583-This is usually an `Error` instance.584-585-[More info.](termination.md#error-message-and-stack-trace)586-587-### error.code588-589-Type: `string | undefined`590-591-Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.592-597 ## Options598 599 Type: `object`600 279 unmodified lines880 Default: `0`881 882 If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.883 880-On timeout, [`result.timedOut`](#resulttimedout) becomes `true`.884+On timeout, [`result.timedOut`](#errortimedout) becomes `true`.885 886 [More info.](termination.md#timeout)887 888 ### options.cancelSignal1 unmodified line890 Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)891 892 You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).893 890-When `AbortController.abort()` is called, [`result.isCanceled`](#resultiscanceled) becomes `true`.894+When `AbortController.abort()` is called, [`result.isCanceled`](#erroriscanceled) becomes `true`.895 896 [More info.](termination.md#canceling)897 898 ### options.forceKillAfterDelay135 unmodified linesmodified:docs/errors.md+5 added-5 removed
34 unmodified lines353637383939404142435 unmodified lines4950515253545556535455565758596061 unmodified lines34 unmodified lines```
## Exit code
The subprocess fails when its [exit code](https://en.wikipedia.org/wiki/Exit_status) is not `0`. The exit code is available as [`error.exitCode`](api.md#resultexitcode). It is `undefined` when the subprocess fails to spawn or when it was [terminated by a signal](termination.md#signal-termination).The subprocess fails when its [exit code](https://en.wikipedia.org/wiki/Exit_status) is not `0`. The exit code is available as [`error.exitCode`](api.md#errorexitcode). It is `undefined` when the subprocess fails to spawn or when it was [terminated by a signal](termination.md#signal-termination).
```jstry { await execa`npm run build`;5 unmodified lines
## Failure reason
The subprocess can fail for other reasons. Some of them can be detected using a specific boolean property:- [`error.timedOut`](api.md#resulttimedout): [`timeout`](termination.md#timeout) option.- [`error.isCanceled`](api.md#resultiscanceled): [`cancelSignal`](termination.md#canceling) option.- [`error.isMaxBuffer`](api.md#resultismaxbuffer): [`maxBuffer`](output.md#big-output) option.- [`error.isTerminated`](api.md#resultisterminated): [signal termination](termination.md#signal-termination). This includes the [`timeout`](termination.md#timeout) and [`cancelSignal`](termination.md#canceling) options since those terminate the subprocess with a [signal](termination.md#default-signal). However, this does not include the [`maxBuffer`](output.md#big-output) option.- [`error.timedOut`](api.md#errortimedout): [`timeout`](termination.md#timeout) option.- [`error.isCanceled`](api.md#erroriscanceled): [`cancelSignal`](termination.md#canceling) option.- [`error.isMaxBuffer`](api.md#errorismaxbuffer): [`maxBuffer`](output.md#big-output) option.- [`error.isTerminated`](api.md#erroristerminated): [signal termination](termination.md#signal-termination). This includes the [`timeout`](termination.md#timeout) and [`cancelSignal`](termination.md#canceling) options since those terminate the subprocess with a [signal](termination.md#default-signal). However, this does not include the [`maxBuffer`](output.md#big-output) option.
Otherwise, the subprocess failed because either:- An exception was thrown in a [stream](streams.md) or [transform](transform.md).- The command's executable file was not found.61 unmodified linesmodified:docs/output.md+1 added-1 removed
138 unmodified lines139 ## Big output140 141 To prevent high memory consumption, a maximum output size can be set using the [`maxBuffer`](api.md#optionsmaxbuffer) option. It defaults to 100MB.142 143-When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](api.md#resultismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](api.md#resultstdout) and [`error.stderr`](api.md#resultstderr).143+When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](api.md#errorismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](api.md#resultstdout) and [`error.stderr`](api.md#resultstderr).144 145 This is measured:146 - By default: in [characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length).147 - If the [`encoding`](binary.md#encoding) option is `'buffer'`: in bytes.28 unmodified linesmodified:docs/termination.md+2 added-2 removed
100 unmodified lines101 ```102 103 ### Signal name and description104 105-When a subprocess was terminated by a signal, [`error.isTerminated`](api.md#resultisterminated) is `true`.105+When a subprocess was terminated by a signal, [`error.isTerminated`](api.md#erroristerminated) is `true`.106 107-Also, [`error.signal`](api.md#resultsignal) and [`error.signalDescription`](api.md#resultsignaldescription) indicate the signal's name and [human-friendly description](https://github.com/ehmicky/human-signals). On Windows, those are only set if the current process terminated the subprocess, as opposed to [another process](#inter-process-termination).107+Also, [`error.signal`](api.md#errorsignal) and [`error.signalDescription`](api.md#errorsignaldescription) indicate the signal's name and [human-friendly description](https://github.com/ehmicky/human-signals). On Windows, those are only set if the current process terminated the subprocess, as opposed to [another process](#inter-process-termination).108 109 ```js110 try {111 await execa`npm run build`;84 unmodified linesmodified:types/return/final-error.d.ts+6 added-2 removed
22 unmodified lines232425262727282930313233343536373638394041424344454622 unmodified lines | 'originalMessage' | 'code';
/**Exception thrown when the subprocess fails.Result of a subprocess failed execution.
This error is thrown as an exception. If the `reject` option is false, it is returned instead.
This has the same shape as successful results, with a few additional properties.*/export class ExecaError<OptionsType extends Options = Options> extends CommonError<false, OptionsType> { readonly name: 'ExecaError';}
/**Exception thrown when the subprocess fails.Result of a subprocess failed execution.
This error is thrown as an exception. If the `reject` option is false, it is returned instead.
This has the same shape as successful results, with a few additional properties.*/export class ExecaSyncError<OptionsType extends SyncOptions = SyncOptions> extends CommonError<true, OptionsType> { readonly name: 'ExecaSyncError';}modified:types/return/result.d.ts+4 added-2 removed
74 unmodified lines75 durationMs: number;76 77 /**78 Whether the subprocess failed to run.79+80+ When this is `true`, the result is an `ExecaError` instance with additional error-related properties.81 */82 failed: boolean;83 84 /**89 unmodified lines174 ? {}175 : {[ErrorProperty in ErrorProperties]: never};176 177 /**176-Result of a subprocess execution.178+Result of a subprocess successful execution.179 180 When the subprocess fails, it is rejected with an `ExecaError` instead.181 */182 export type ExecaResult<OptionsType extends Options = Options> = SuccessResult<false, OptionsType>;183 184 /**183-Result of a subprocess execution.185+Result of a subprocess successful execution.186 187 When the subprocess fails, it is rejected with an `ExecaError` instead.188 */189 export type ExecaSyncResult<OptionsType extends SyncOptions = SyncOptions> = SuccessResult<true, OptionsType>;