Skip to content
Myr

errors.md

This file

Path

docs/errors.md

112 lines · 4.7 KiB · Markdown

Last changed by

TweaksSindre Sorhusbefore adoption54d7404

History of this file

Take it

The walk stopped after 200 commits: lines older than c78ae5c point at it.

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 1–10why, one step back
1<picture>
2 <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3 <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>67# ❌ Errors89## Subprocess failure10

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 11why, one step back
11When the subprocess fails, the promise returned by [`execa()`](api.md#execafile-arguments-options) is rejected with an [`ExecaError`](api.md#execaerror) instance. The `error` has the same shape as successful [results](api.md#result), with a few additional [error-specific fields](api.md#execaerror). [`error.failed`](api.md#resultfailed) is always `true`.

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

line 12why, one step back
12

TweaksSindre Sorhusbefore adoption54d7404

lines 13–14why, one step back
13When the subprocess fails to spawn, its output ([`error.stdout`](api.md#resultstdout), [`error.stderr`](api.md#resultstderr), [`error.all`](api.md#resultall) and [`error.stdio`](api.md#resultstdio)) is usually empty. With some errors, it is `undefined` instead.
14

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 15–29why, one step back
15```js
16import {execa, ExecaError} from 'execa';1718try {19 const result = await execa`npm run build`;20 console.log(result.failed); // false21} catch (error) {22 if (error instanceof ExecaError) {23 console.error(error.failed); // true24 }25}26```2728## Preventing exceptions29

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 30why, one step back
30When the [`reject`](api.md#optionsreject) option is `false`, the `error` is returned instead.

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 31–32why, one step back
31
32```js

Fix "Preventing exceptions" example (#1110)Karl Horkybefore adoptiona5a4d69

line 33why, one step back
33const resultOrError = await execa({reject: false})`npm run build`;

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 34–40why, one step back
34if (resultOrError.failed) {
35 console.error(resultOrError);36}37```3839## Exit code40

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 41why, one step back
41The 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).

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 42–54why, one step back
42
43```js44try {45 await execa`npm run build`;46} catch (error) {47 // Either non-0 integer or undefined48 console.error(error.exitCode);49}50```5152## Failure reason5354The subprocess can fail for other reasons. Some of them can be detected using a specific boolean property:

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

lines 55–56why, one step back
55- [`error.timedOut`](api.md#errortimedout): [`timeout`](termination.md#timeout) option.
56- [`error.isCanceled`](api.md#erroriscanceled): [`cancelSignal`](termination.md#canceling) option.

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 57why, one step back
57- [`error.isGracefullyCanceled`](api.md#errorisgracefullycanceled): `cancelSignal` option, if the [`gracefulCancel`](termination.md#graceful-termination) option is `true`.

Improve documentation of `error.*` fields (#1006)ehmickybefore adoption4ee0dec

line 58why, one step back
58- [`error.isMaxBuffer`](api.md#errorismaxbuffer): [`maxBuffer`](output.md#big-output) option.

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 59why, one step back
59- [`error.isTerminated`](api.md#erroristerminated): [signal termination](termination.md#signal-termination). This includes the [`timeout`](termination.md#timeout) and [`forceKillAfterDelay`](termination.md#forceful-termination) options since those terminate the subprocess with a [signal](termination.md#default-signal). This also includes the [`cancelSignal`](termination.md#canceling) option unless the [`gracefulCancel`](termination.md#graceful-termination) option is `true`. This does not include the [`maxBuffer`](output.md#big-output) option.

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 60–63why, one step back
60
61Otherwise, the subprocess failed because either:62- An exception was thrown in a [stream](streams.md) or [transform](transform.md).63- The command's executable file was not found.

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 64why, one step back
64- An invalid [option](api.md#options-1) was passed.

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 65–80why, one step back
65- There was not enough memory or too many subprocesses.
6667```js68try {69 await execa`npm run build`;70} catch (error) {71 if (error.timedOut) {72 handleTimeout(error);73 }7475 throw error;76}77```7879## Error message80

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 81why, one step back
81For better [debugging](debugging.md), [`error.message`](api.md#errormessage) includes both:

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

line 82why, one step back
82- The command and the [reason it failed](#failure-reason).

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

line 83why, one step back
83- Its [`stdout`, `stderr`](output.md#stdout-and-stderr), [other file descriptors'](output.md#additional-file-descriptors) output and [IPC messages](ipc.md), separated with newlines and not [interleaved](output.md#interleaved-output).

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

line 84why, one step back
84

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

line 85why, one step back
85[`error.shortMessage`](api.md#errorshortmessage) is the same but without `stdout`, `stderr` nor IPC messages.

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

line 86why, one step back
86

Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813

line 87why, one step back
87[`error.originalMessage`](api.md#errororiginalmessage) is the same but also without the command. This exists only in specific instances, such as when calling [`subprocess.kill(error)`](termination.md#error-message-and-stack-trace), using the [`cancelSignal`](termination.md#canceling) option, passing an invalid command or [option](api.md#options-1), or throwing an exception in a [stream](streams.md) or [transform](transform.md).

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 88–112why, one step back
88
89```js90try {91 await execa`npm run build`;92} catch (error) {93 console.error(error.originalMessage);94 // The task "build" does not exist.9596 console.error(error.shortMessage);97 // Command failed with exit code 3: npm run build98 // The task "build" does not exist.99100 console.error(error.message);101 // Command failed with exit code 3: npm run build102 // The task "build" does not exist.103 // [stderr contents...]104 // [stdout contents...]105}106```107108<hr>109110[**Next**: 🏁 Termination](termination.md)\111[**Previous**: 🌐 Environment](environment.md)\112[**Top**: Table of contents](../readme.md#documentation)