Skip to content
Myr

Fix shape of exceptions thrown by `execa.sync()` (#277)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent 50a924a · Browse files · 2 files+17 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−5 removed

  • other:+17 added−5 removed

2 files+17 added−5 removed

modified:index.js+13 added-1 removed
413 unmodified lines
414 if (isStream(parsed.options.input)) {415 throw new TypeError('The `input` option cannot be a stream in sync mode');416 }417418 let result;419 try {418 const result = childProcess.spawnSync(parsed.file, parsed.args, parsed.options);420 result = childProcess.spawnSync(parsed.file, parsed.args, parsed.options);421 } catch (error) {422 throw makeError({error, stdout: '', stderr: '', all: ''}, {423 joinedCommand,424 parsed,425 timedOut: false,426 isCanceled: false,427 killed: false428 });429 }430431 result.stdout = handleOutput(parsed.options, result.stdout, result.error);432 result.stderr = handleOutput(parsed.options, result.stderr, result.error);433434 if (result.error || result.status !== 0 || result.signal !== null) {
60 unmodified lines
modified:test.js+4 added-4 removed
291 unmodified lines
292 const {exitCodeName} = await t.throwsAsync(execa('noop', {uid: -1}));293 t.is(exitCodeName, process.platform === 'win32' ? 'ENOTSUP' : 'EINVAL');294});295296test('child_process.spawnSync() errors are propagated', t => {297 const {exitCodeName} = t.throws(() => {298 execa.sync('noop', {uid: -1});296test('child_process.spawnSync() errors are propagated with a correct shape', t => {297 const {failed} = t.throws(() => {298 execa.sync('noop', {timeout: -1});299 });300 t.is(exitCodeName, process.platform === 'win32' ? 'ENOTSUP' : 'EINVAL');300 t.true(failed);301});302303test('maxBuffer affects stdout', async t => {304 await t.throwsAsync(execa('max-buffer', ['stdout', '11'], {maxBuffer: 10}), /stdout maxBuffer exceeded/);
496 unmodified lines