Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages when an error event is emitted #269

Merged
merged 4 commits into from May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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