Skip to content

Commit

Permalink
Make errors more consistent (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored and sindresorhus committed May 29, 2019
1 parent 6853316 commit e5ed8de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
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
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

0 comments on commit e5ed8de

Please sign in to comment.