From e5ed8de1cfa24c781442dcef4d9e4943790cf2f5 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Wed, 29 May 2019 11:47:25 -0700 Subject: [PATCH] Make errors more consistent (#266) --- index.js | 8 +++++++- test.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index bb3d217c2f..0bdf14833c 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/test.js b/test.js index aa74acd5e4..fb0cd8aecf 100644 --- a/test.js +++ b/test.js @@ -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}));