Improve handling of early errors (#906)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 4577582 · Browse files · 2 files·+13 added−10 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+13 added−10 removed
- tests:+9 added−7 removed
- other:+4 added−3 removed
Provenance
- Commit
2bb9535- Tree
d9fdde9- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
4577582
2 files changed+13 added−10 removed
modified:lib/return/early-error.js+4 added-3 removed
8 unmodified lines91011121313141516171819202021222324252526272829306 unmodified lines8 unmodified linesexport const handleEarlyError = ({error, command, escapedCommand, stdioStreamsGroups, options, startTime, verboseInfo}) => { cleanupStdioStreams(stdioStreamsGroups);
const subprocess = new ChildProcess(); createDummyStreams(subprocess); createDummyStreams(subprocess, stdioStreamsGroups);
const earlyError = makeEarlyError({error, command, escapedCommand, stdioStreamsGroups, options, startTime}); const promise = handleDummyPromise(earlyError, verboseInfo, options); return {subprocess, promise};};
const createDummyStreams = subprocess => {const createDummyStreams = (subprocess, stdioStreamsGroups) => { const stdin = createDummyStream(); const stdout = createDummyStream(); const stderr = createDummyStream(); const extraStdio = Array.from({length: stdioStreamsGroups.length - 3}, createDummyStream); const all = createDummyStream(); const stdio = [stdin, stdout, stderr]; const stdio = [stdin, stdout, stderr, ...extraStdio]; Object.assign(subprocess, {stdin, stdout, stderr, all, stdio});};
const createDummyStream = () => {6 unmodified linesmodified:test/return/early-error.js+9 added-7 removed
12345678967 unmodified lines7778798080818182838485868788898990919293909192939495import process from 'node:process';import test from 'ava';import {execa, execaSync, $} from '../../index.js';import {setFixtureDir} from '../helpers/fixtures-dir.js';import {fullStdio} from '../helpers/stdio.js';import {earlyErrorOptions, getEarlyErrorSubprocess, getEarlyErrorSubprocessSync, expectedEarlyError} from '../helpers/early-error.js';
setFixtureDir();
67 unmodified linestest('child_process.spawn() early errors can use .pipe() multiple times', testEarlyErrorPipe, () => getEarlyErrorSubprocess().pipe(getEarlyErrorSubprocess()).pipe(getEarlyErrorSubprocess()));test('child_process.spawn() early errors can use .pipe``', testEarlyErrorPipe, () => $(earlyErrorOptions)`empty.js`.pipe(earlyErrorOptions)`empty.js`);test('child_process.spawn() early errors can use .pipe`` multiple times', testEarlyErrorPipe, () => $(earlyErrorOptions)`empty.js`.pipe(earlyErrorOptions)`empty.js`.pipe`empty.js`);
const testEarlyErrorStream = async (t, getStreamProperty, all) => { const subprocess = getEarlyErrorSubprocess({all});const testEarlyErrorStream = async (t, getStreamProperty, options) => { const subprocess = getEarlyErrorSubprocess(options); const stream = getStreamProperty(subprocess); stream.on('close', () => {}); stream.read?.(); stream.end?.(); await t.throwsAsync(subprocess);};
test('child_process.spawn() early errors can use .stdin', testEarlyErrorStream, ({stdin}) => stdin, false);test('child_process.spawn() early errors can use .stdout', testEarlyErrorStream, ({stdout}) => stdout, false);test('child_process.spawn() early errors can use .stderr', testEarlyErrorStream, ({stderr}) => stderr, false);test('child_process.spawn() early errors can use .stdio', testEarlyErrorStream, ({stdio}) => stdio[1], false);test('child_process.spawn() early errors can use .all', testEarlyErrorStream, ({all}) => all, true);test('child_process.spawn() early errors can use .stdin', testEarlyErrorStream, ({stdin}) => stdin);test('child_process.spawn() early errors can use .stdout', testEarlyErrorStream, ({stdout}) => stdout);test('child_process.spawn() early errors can use .stderr', testEarlyErrorStream, ({stderr}) => stderr);test('child_process.spawn() early errors can use .stdio[1]', testEarlyErrorStream, ({stdio}) => stdio[1]);test('child_process.spawn() early errors can use .stdio[3]', testEarlyErrorStream, ({stdio}) => stdio[3], fullStdio);test('child_process.spawn() early errors can use .all', testEarlyErrorStream, ({all}) => all, {all: true});