diff --git a/index.js b/index.js index 0883ebe676..f7b4ef8ecc 100644 --- a/index.js +++ b/index.js @@ -415,7 +415,19 @@ module.exports.sync = (file, args, options) => { throw new TypeError('The `input` option cannot be a stream in sync mode'); } - const result = childProcess.spawnSync(parsed.file, parsed.args, parsed.options); + let result; + try { + result = childProcess.spawnSync(parsed.file, parsed.args, parsed.options); + } catch (error) { + throw makeError({error, stdout: '', stderr: '', all: ''}, { + joinedCommand, + parsed, + timedOut: false, + isCanceled: false, + killed: false + }); + } + result.stdout = handleOutput(parsed.options, result.stdout, result.error); result.stderr = handleOutput(parsed.options, result.stderr, result.error); diff --git a/test.js b/test.js index 5249888a11..a392ca2403 100644 --- a/test.js +++ b/test.js @@ -293,11 +293,11 @@ test('child_process.spawn() errors are propagated', async t => { 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}); +test('child_process.spawnSync() errors are propagated with a correct shape', t => { + const {failed} = t.throws(() => { + execa.sync('noop', {timeout: -1}); }); - t.is(exitCodeName, process.platform === 'win32' ? 'ENOTSUP' : 'EINVAL'); + t.true(failed); }); test('maxBuffer affects stdout', async t => {