Skip to content

Commit

Permalink
Improve error messages when an error event is emitted (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored and sindresorhus committed May 30, 2019
1 parent 3b103f8 commit 2307d95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -198,7 +198,11 @@ function getErrorPrefix({timedOut, timeout, signal, exitCodeName, exitCode, isCa
return `was killed with ${signal}`;
}

return `failed with exit code ${exitCode} (${exitCodeName})`;
if (exitCode !== undefined) {
return `failed with exit code ${exitCode} (${exitCodeName})`;
}

return 'failed';
}

function joinCommand(file, args = []) {
Expand Down
6 changes: 6 additions & 0 deletions test.js
Expand Up @@ -194,6 +194,12 @@ test('input option can be a Buffer - sync', t => {
t.is(stdout, 'testing12');
});

test('child process errors are handled', async t => {
const child = execa('noop');
child.emit('error', new Error('test'));
await t.throwsAsync(child, /Command failed.*\ntest/);
});

test('opts.stdout:ignore - stdout will not collect data', async t => {
const {stdout} = await execa('stdin', {
input: 'hello',
Expand Down

0 comments on commit 2307d95

Please sign in to comment.