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

Make errors more consistent #266

Merged
merged 1 commit into from
May 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ const execa = (file, args, options) => {
try {
spawned = childProcess.spawn(parsed.file, parsed.args, parsed.options);
} catch (error) {
return Promise.reject(error);
return Promise.reject(makeError({error, stdout: '', stderr: '', all: ''}, {
joinedCommand,
parsed,
timedOut: false,
isCanceled: false,
killed: false
}));
}

// #115
Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ test('execa() returns a promise with kill() and pid', t => {
t.is(typeof pid, 'number');
});

test('child_process.spawn() errors are propagated', async t => {
const {exitCodeName} = await t.throwsAsync(execa('noop', {uid: -1}));
t.is(exitCodeName, process.platform === 'win32' ? 'ENOTSUP' : 'EINVAL');
});

test('child_process.spawnSync() errors are propagated', t => {
const {exitCodeName} = t.throws(() => {
execa.sync('noop', {uid: -1});
});
t.is(exitCodeName, process.platform === 'win32' ? 'ENOTSUP' : 'EINVAL');
});

test('maxBuffer affects stdout', async t => {
await t.throwsAsync(execa('max-buffer', ['stdout', '11'], {maxBuffer: 10}), /stdout maxBuffer exceeded/);
await t.notThrowsAsync(execa('max-buffer', ['stdout', '10'], {maxBuffer: 10}));
Expand Down