Skip to content

Commit

Permalink
Fix error thrown when options are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 10, 2019
1 parent a7b57d9 commit 2ec2a70
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -247,13 +247,13 @@ const execa = (file, args, options) => {
try {
spawned = childProcess.spawn(parsed.file, parsed.args, parsed.options);
} catch (error) {
return Promise.reject(makeError({error, stdout: '', stderr: '', all: ''}, {
throw makeError({error, stdout: '', stderr: '', all: ''}, {
joinedCommand,
parsed,
timedOut: false,
isCanceled: false,
killed: false
}));
});
}

const kill = spawned.kill.bind(spawned);
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Expand Up @@ -136,6 +136,8 @@ Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#c
- is also a `Promise` resolving or rejecting with a [`childProcessResult`](#childProcessResult).
- exposes the following additional methods and properties.

An [error](#childProcessResult) might also be thrown when `options` are invalid.

#### kill([signal], [options])

Same as the original [`child_process#kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal) except: if `signal` is `SIGTERM` (the default value) and the child process is not terminated after 5 seconds, force it by sending `SIGKILL`.
Expand Down
4 changes: 2 additions & 2 deletions test.js
Expand Up @@ -288,8 +288,8 @@ 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}));
test('child_process.spawn() errors are propagated', t => {
const {exitCodeName} = t.throws(() => execa('noop', {uid: -1}));
t.is(exitCodeName, process.platform === 'win32' ? 'ENOTSUP' : 'EINVAL');
});

Expand Down

0 comments on commit 2ec2a70

Please sign in to comment.