Skip to content

Commit 4cafa60

Browse files
sam-githubjasnell
authored andcommitted
child_process: align fork/spawn stdio error msg
fork()'s support for .stdio strings in 3268863 used a different TypeError string from spawn, unnecessarily. PR-URL: #11044 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent 7818245 commit 4cafa60

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

lib/child_process.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ const setupChannel = child_process.setupChannel;
1818
const ChildProcess = exports.ChildProcess = child_process.ChildProcess;
1919

2020
function stdioStringToArray(option) {
21-
return [option, option, option, 'ipc'];
21+
switch (option) {
22+
case 'ignore':
23+
case 'pipe':
24+
case 'inherit':
25+
return [option, option, option, 'ipc'];
26+
default:
27+
throw new TypeError('Incorrect value of stdio option: ' + option);
28+
}
2229
}
2330

2431
exports.fork = function(modulePath /*, args, options*/) {
@@ -55,15 +62,7 @@ exports.fork = function(modulePath /*, args, options*/) {
5562
args = execArgv.concat([modulePath], args);
5663

5764
if (typeof options.stdio === 'string') {
58-
switch (options.stdio) {
59-
case 'ignore':
60-
case 'pipe':
61-
case 'inherit':
62-
options.stdio = stdioStringToArray(options.stdio);
63-
break;
64-
default:
65-
throw new TypeError('Unknown stdio option');
66-
}
65+
options.stdio = stdioStringToArray(options.stdio);
6766
} else if (!Array.isArray(options.stdio)) {
6867
// Use a separate fd=3 for the IPC channel. Inherit stdin, stdout,
6968
// and stderr from the parent if silent isn't set.

test/parallel/test-child-process-fork-stdio-string-variant.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const assert = require('assert');
99
const fork = require('child_process').fork;
1010

1111
const childScript = `${common.fixturesDir}/child-process-spawn-node`;
12-
const errorRegexp = /^TypeError: Unknown stdio option$/;
12+
const errorRegexp = /^TypeError: Incorrect value of stdio option:/;
1313
const malFormedOpts = {stdio: '33'};
1414
const payload = {hello: 'world'};
1515
const stringOpts = {stdio: 'pipe'};

0 commit comments

Comments
 (0)