From 2ec2a70bd2870b1066068db002288f22cc578af3 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Thu, 6 Jun 2019 10:00:00 +0200 Subject: [PATCH] Fix error thrown when options are invalid --- index.js | 4 ++-- readme.md | 2 ++ test.js | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 34bf68b89f..13f830b004 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/readme.md b/readme.md index 6ce453c1b5..9ffe728f9d 100644 --- a/readme.md +++ b/readme.md @@ -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`. diff --git a/test.js b/test.js index 5249888a11..c1e322f72b 100644 --- a/test.js +++ b/test.js @@ -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'); });