Skip to content
Myr

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

6 files+85 added−75 removed

modified:docs/api.md+67 added-63 removed
191 unmodified lines
192`signal`: `string | number`\193`error`: `Error`\194_Returns_: `boolean`195196Sends 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.196Sends 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.197198This returns `false` when the signal could not be sent, for example when the subprocess has already exited.199200When 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 lines
368## Result369370Type: `object`371372[Result](execution.md#result) of a subprocess execution.372[Result](execution.md#result) of a subprocess successful execution.373374When the subprocess [fails](errors.md#subprocess-failure), it is rejected with an [`ExecaError`](#execaerror) instead.375376### result.stdout
93 unmodified lines
470Type: `boolean`471472Whether the subprocess failed to run.473474When this is `true`, the result is an [`ExecaError`](#execaerror) instance with additional error-related properties.475476[More info.](errors.md#subprocess-failure)477476### result.timedOut478## ExecaError479## ExecaSyncError480481Type: `Error`482483Result of a subprocess [failed execution](errors.md#subprocess-failure).484485This error is thrown as an exception. If the [`reject`](#optionsreject) option is false, it is returned instead.486487This has the same shape as [successful results](#result), with the following additional properties.488489[More info.](errors.md)490491### error.message492493Type: `string`494495Error message when the subprocess [failed](errors.md#subprocess-failure) to run.496497[More info.](errors.md#error-message)498499### error.shortMessage500501Type: `string`502503This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).504505[More info.](errors.md#error-message)506507### error.originalMessage508509Type: `string | undefined`510511Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.512513[More info.](errors.md#error-message)514515### error.cause516517Type: `unknown | undefined`518519Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).520521This is usually an `Error` instance.522523[More info.](termination.md#error-message-and-stack-trace)524525### error.code526527Type: `string | undefined`528529Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.530531### error.timedOut532533Type: `boolean`534535Whether the subprocess timed out due to the [`timeout`](#optionstimeout) option.536537[More info.](termination.md#timeout)538484### result.isCanceled539### error.isCanceled540541Type: `boolean`542543Whether the subprocess was canceled using the [`cancelSignal`](#optionscancelsignal) option.544545[More info.](termination.md#canceling)546492### result.isMaxBuffer547### error.isMaxBuffer548549Type: `boolean`550551Whether the subprocess failed because its output was larger than the [`maxBuffer`](#optionsmaxbuffer) option.552553[More info.](output.md#big-output)554500### result.isTerminated555### error.isTerminated556557Type: `boolean`558559Whether the subprocess was terminated by a [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) sent by either:
1 unmodified line
561- [Another process](termination.md#inter-process-termination). This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).562563[More info.](termination.md#signal-name-and-description)564510### result.exitCode565### error.exitCode566567Type: `number | undefined`568569The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.570516This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#resultsignal).571This is `undefined` when the subprocess could not be spawned or was terminated by a [signal](#errorsignal).572573[More info.](errors.md#exit-code)574520### result.signal575### error.signal576577Type: `string | undefined`578579The name of the [signal](termination.md#signal-termination) (like [`SIGTERM`](termination.md#sigterm)) that terminated the subprocess, sent by either:
3 unmodified lines
583If a signal terminated the subprocess, this property is defined and included in the [error message](#errormessage). Otherwise it is `undefined`.584585[More info.](termination.md#signal-name-and-description)586532### result.signalDescription587### error.signalDescription588589Type: `string | undefined`590591A human-friendly description of the [signal](termination.md#signal-termination) that was used to terminate the subprocess.
1 unmodified line
593If 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.594595[More info.](termination.md#signal-name-and-description)596542## ExecaError543## ExecaSyncError544545Type: `Error`546547Exception thrown when the subprocess [fails](errors.md#subprocess-failure).548549This has the same shape as [successful results](#result), with the following additional properties.550551[More info.](errors.md)552553### error.message554555Type: `string`556557Error message when the subprocess [failed](errors.md#subprocess-failure) to run.558559[More info.](errors.md#error-message)560561### error.shortMessage562563Type: `string`564565This is the same as [`error.message`](#errormessage) except it does not include the subprocess [output](output.md).566567[More info.](errors.md#error-message)568569### error.originalMessage570571Type: `string | undefined`572573Original error message. This is the same as [`error.message`](#errormessage) excluding the subprocess [output](output.md) and some additional information added by Execa.574575[More info.](errors.md#error-message)576577### error.cause578579Type: `unknown | undefined`580581Underlying error, if there is one. For example, this is set by [`subprocess.kill(error)`](#subprocesskillerror).582583This is usually an `Error` instance.584585[More info.](termination.md#error-message-and-stack-trace)586587### error.code588589Type: `string | undefined`590591Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.592597## Options598599Type: `object`600
279 unmodified lines
880Default: `0`881882If `timeout` is greater than `0`, the subprocess will be [terminated](#optionskillsignal) if it runs for longer than that amount of milliseconds.883880On timeout, [`result.timedOut`](#resulttimedout) becomes `true`.884On timeout, [`result.timedOut`](#errortimedout) becomes `true`.885886[More info.](termination.md#timeout)887888### options.cancelSignal
1 unmodified line
890Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)891892You can abort the subprocess using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).893890When `AbortController.abort()` is called, [`result.isCanceled`](#resultiscanceled) becomes `true`.894When `AbortController.abort()` is called, [`result.isCanceled`](#erroriscanceled) becomes `true`.895896[More info.](termination.md#canceling)897898### options.forceKillAfterDelay
135 unmodified lines
modified:docs/errors.md+5 added-5 removed
modified:docs/output.md+1 added-1 removed
138 unmodified lines
139## Big output140141To prevent high memory consumption, a maximum output size can be set using the [`maxBuffer`](api.md#optionsmaxbuffer) option. It defaults to 100MB.142143When 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).143When 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).144145This 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 lines
modified:docs/termination.md+2 added-2 removed
100 unmodified lines
101```102103### Signal name and description104105When a subprocess was terminated by a signal, [`error.isTerminated`](api.md#resultisterminated) is `true`.105When a subprocess was terminated by a signal, [`error.isTerminated`](api.md#erroristerminated) is `true`.106107Also, [`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).107Also, [`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).108109```js110try {111 await execa`npm run build`;
84 unmodified lines
modified:types/return/final-error.d.ts+6 added-2 removed
modified:types/return/result.d.ts+4 added-2 removed
74 unmodified lines
75 durationMs: number;7677 /**78 Whether the subprocess failed to run.7980 When this is `true`, the result is an `ExecaError` instance with additional error-related properties.81 */82 failed: boolean;8384 /**
89 unmodified lines
174 ? {}175 : {[ErrorProperty in ErrorProperties]: never};176177/**176Result of a subprocess execution.178Result of a subprocess successful execution.179180When the subprocess fails, it is rejected with an `ExecaError` instead.181*/182export type ExecaResult<OptionsType extends Options = Options> = SuccessResult<false, OptionsType>;183184/**183Result of a subprocess execution.185Result of a subprocess successful execution.186187When the subprocess fails, it is rejected with an `ExecaError` instead.188*/189export type ExecaSyncResult<OptionsType extends SyncOptions = SyncOptions> = SuccessResult<true, OptionsType>;