Skip to content
Myr

Add stdout/stderr to error messages (#397)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent 09cd28a · Browse files · 6 files+62 added−11 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+62 added−11 removed

  • tests:+24 added−1 removed
  • other:+38 added−10 removed

6 files+62 added−11 removed

modified:lib/error.js+5 added-2 removed
added:test/fixtures/echo-fail+5 added
1#!/usr/bin/env node2'use strict';3console.log('stdout');4console.error('stderr');5process.exit(1);
modified:test/error.js+19 added-1 removed
49 unmodified lines
50test('exitCode is 3', testExitCode, 3);51test('exitCode is 4', testExitCode, 4);5253test('error.message contains the command', async t => {54 await t.throwsAsync(execa('exit', ['2', 'foo', 'bar'], {message: /exit 2 foo bar/}));54 await t.throwsAsync(execa('exit', ['2', 'foo', 'bar']), {message: /exit 2 foo bar/});55});5657test('error.message contains stdout/stderr if available', async t => {58 const {message} = await t.throwsAsync(execa('echo-fail'));59 t.true(message.includes('stderr'));60 t.true(message.includes('stdout'));61});6263test('error.message does not contain stdout/stderr if not available', async t => {64 const {message} = await t.throwsAsync(execa('echo-fail', {stdio: 'ignore'}));65 t.false(message.includes('stderr'));66 t.false(message.includes('stdout'));67});6869test('error.shortMessage does not contain stdout/stderr', async t => {70 const {shortMessage} = await t.throwsAsync(execa('echo-fail'));71 t.false(shortMessage.includes('stderr'));72 t.false(shortMessage.includes('stdout'));73});7475test('Original error.message is kept', async t => {76 const {originalMessage} = await t.throwsAsync(execa('wrong command'));77 t.is(originalMessage, 'spawn wrong command ENOENT');78});
132 unmodified lines
modified:index.d.ts+11 added-4 removed
42 unmodified lines
4344 This can be either an absolute path or a path relative to the `cwd` option.4546 Requires `preferLocal` to be `true`.47 4748 For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process.4950 @default process.execPath51 */
283 unmodified lines
335 interface ExecaSyncError<StdoutErrorType = string>336 extends Error,337 ExecaReturnBase<StdoutErrorType> {338 /**339 The error message.339 Error message when the child process failed to run. In addition to the underlying error message, it also contains some information related to why the child process errored.340341 The child process stderr then stdout are appended to the end, separated with newlines and not interleaved.342 */343 message: string;344345 /**344 Original error message. This is `undefined` unless the child process exited due to an `error` event or a timeout.346 This is the same as the `message` property except it does not include the child process stdout/stderr.347 */348 shortMessage: string;349346 The `message` property contains both the `originalMessage` and some additional information added by Execa.350 /**351 Original error message. This is the same as the `message` property except it includes neither the child process stdout/stderr nor some additional information added by Execa.352353 This is `undefined` unless the child process exited due to an `error` event or a timeout.354 */355 originalMessage?: string;356 }357
192 unmodified lines
modified:index.test-d.ts+2 added
38 unmodified lines
39 expectType<boolean>(execaError.isCanceled);40 expectType<boolean>(execaError.killed);41 expectType<string | undefined>(execaError.signal);42 expectType<string | undefined>(execaError.signalDescription);43 expectType<string>(execaError.shortMessage);44 expectType<string | undefined>(execaError.originalMessage);45}4647try {
22 unmodified lines
70 expectError(execaError.isCanceled);71 expectType<boolean>(execaError.killed);72 expectType<string | undefined>(execaError.signal);73 expectType<string | undefined>(execaError.signalDescription);74 expectType<string>(execaError.shortMessage);75 expectType<string | undefined>(execaError.originalMessage);76}7778execa('unicorns', {cleanup: false});
113 unmodified lines
modified:readme.md+20 added-4 removed
58 unmodified lines
59 console.log(error);60 /*61 {62 message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',63 errno: 'ENOENT',63 errno: -2,64 code: 'ENOENT',65 syscall: 'spawn unknown',66 path: 'unknown',67 spawnargs: ['command'],68 originalMessage: 'spawn unknown ENOENT',69 shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',70 command: 'unknown command',71 stdout: '',72 stderr: '',73 all: '',
38 unmodified lines
112 console.log(error);113 /*114 {115 message: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT',115 errno: 'ENOENT',116 errno: -2,117 code: 'ENOENT',118 syscall: 'spawnSync unknown',119 path: 'unknown',120 spawnargs: ['command'],121 originalMessage: 'spawnSync unknown ENOENT',122 shortMessage: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT',123 command: 'unknown command',124 stdout: '',125 stderr: '',126 all: '',
176 unmodified lines
303A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`.304305If a signal terminated the process, 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.306307#### message308309Type: `string`310311Error message when the child process failed to run. In addition to the [underlying error message](#originalMessage), it also contains some information related to why the child process errored.312313The child process [stderr](#stderr) then [stdout](#stdout) are appended to the end, separated with newlines and not interleaved.314315#### shortMessage316317Type: `string`318319This is the same as the [`message` property](#message) except it does not include the child process stdout/stderr.320321#### originalMessage322323Type: `string | undefined`324309Original error message. This is `undefined` unless the child process exited due to an `error` event or a timeout.325Original error message. This is the same as the `message` property except it includes neither the child process stdout/stderr nor some additional information added by Execa.326311The `message` property contains both the `originalMessage` and some additional information added by Execa.327This is `undefined` unless the child process exited due to an `error` event or a timeout.328329### options330331Type: `object`
318 unmodified lines