From 4cafa60c99f0d755b1df3a29357e19a92b97eed8 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 30 Jan 2017 13:52:09 -0800 Subject: [PATCH] child_process: align fork/spawn stdio error msg fork()'s support for .stdio strings in 3268863eb used a different TypeError string from spawn, unnecessarily. PR-URL: https://github.com/nodejs/node/pull/11044 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Sam Roberts Reviewed-By: Brian White --- lib/child_process.js | 19 +++++++++---------- ...child-process-fork-stdio-string-variant.js | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 409dfff170cf4a..24f52f94d49209 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -18,7 +18,14 @@ const setupChannel = child_process.setupChannel; const ChildProcess = exports.ChildProcess = child_process.ChildProcess; function stdioStringToArray(option) { - return [option, option, option, 'ipc']; + switch (option) { + case 'ignore': + case 'pipe': + case 'inherit': + return [option, option, option, 'ipc']; + default: + throw new TypeError('Incorrect value of stdio option: ' + option); + } } exports.fork = function(modulePath /*, args, options*/) { @@ -55,15 +62,7 @@ exports.fork = function(modulePath /*, args, options*/) { args = execArgv.concat([modulePath], args); if (typeof options.stdio === 'string') { - switch (options.stdio) { - case 'ignore': - case 'pipe': - case 'inherit': - options.stdio = stdioStringToArray(options.stdio); - break; - default: - throw new TypeError('Unknown stdio option'); - } + options.stdio = stdioStringToArray(options.stdio); } else if (!Array.isArray(options.stdio)) { // Use a separate fd=3 for the IPC channel. Inherit stdin, stdout, // and stderr from the parent if silent isn't set. diff --git a/test/parallel/test-child-process-fork-stdio-string-variant.js b/test/parallel/test-child-process-fork-stdio-string-variant.js index 93676892b632dc..51c943da090c71 100644 --- a/test/parallel/test-child-process-fork-stdio-string-variant.js +++ b/test/parallel/test-child-process-fork-stdio-string-variant.js @@ -9,7 +9,7 @@ const assert = require('assert'); const fork = require('child_process').fork; const childScript = `${common.fixturesDir}/child-process-spawn-node`; -const errorRegexp = /^TypeError: Unknown stdio option$/; +const errorRegexp = /^TypeError: Incorrect value of stdio option:/; const malFormedOpts = {stdio: '33'}; const payload = {hello: 'world'}; const stringOpts = {stdio: 'pipe'};