Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[squash] fix linter
  • Loading branch information
maclover7 committed Nov 28, 2017
commit d160c524ca9b7134b38bda393c377c5777d899b7
69 changes: 53 additions & 16 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ exports.fork = function(modulePath /*, args, options*/) {

if (pos < arguments.length && arguments[pos] != null) {
if (typeof arguments[pos] !== 'object') {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', ('arguments[' + pos + ']'), arguments[pos]);
throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
('arguments[' + pos + ']'),
arguments[pos]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one feels super odd to me... will think about this a bit more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Felt odd to me too, and still mulling over how to properly present this state to users 😞

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a ERR_INVALID_ARG_TYPE though? Judging from the code below I would say it's options that has the wrong type?

}

options = util._extend({}, arguments[pos++]);
Expand Down Expand Up @@ -92,7 +94,9 @@ exports.fork = function(modulePath /*, args, options*/) {
options.stdio = options.silent ? stdioStringToArray('pipe') :
stdioStringToArray('inherit');
} else if (options.stdio.indexOf('ipc') === -1) {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'options.stdio', options.stdio);
throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'options.stdio',
options.stdio);
}

options.execPath = options.execPath || process.execPath;
Expand Down Expand Up @@ -196,7 +200,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
}

if (!callback && pos < arguments.length && arguments[pos] != null) {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'args' , arguments);
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'args', arguments);
}

// Validate the timeout, if present.
Expand Down Expand Up @@ -323,7 +327,8 @@ exports.execFile = function(file /*, args, options, callback*/) {
stdoutLen += encoding ? Buffer.byteLength(chunk, encoding) : chunk.length;

if (stdoutLen > options.maxBuffer) {
// TODO helpful to convert to ERR_BUFFER_OUT_OF_BOUNDS? can't specify stderr/stdout.
// TODO helpful to convert to ERR_BUFFER_OUT_OF_BOUNDS?
// can't specify stderr/stdout with that new error.
ex = new Error('stdout maxBuffer exceeded');
kill();
} else if (encoding) {
Expand All @@ -342,7 +347,8 @@ exports.execFile = function(file /*, args, options, callback*/) {
stderrLen += encoding ? Buffer.byteLength(chunk, encoding) : chunk.length;

if (stderrLen > options.maxBuffer) {
// TODO helpful to convert to ERR_BUFFER_OUT_OF_BOUNDS? can't specify stderr/stdout.
// TODO helpful to convert to ERR_BUFFER_OUT_OF_BOUNDS?
// can't specify stderr/stdout with that new error.
ex = new Error('stderr maxBuffer exceeded');
kill();
} else if (encoding) {
Expand Down Expand Up @@ -395,41 +401,62 @@ function normalizeSpawnArguments(file, args, options) {
if (options === undefined)
options = {};
else if (options === null || typeof options !== 'object')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object', options);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options',
'object',
options);

// Validate the cwd, if present.
if (options.cwd != null &&
typeof options.cwd !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.cwd', 'string', options.cwd);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.cwd',
'string',
options.cwd);
}

// Validate detached, if present.
if (options.detached != null &&
typeof options.detached !== 'boolean') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.detached', 'boolean', options.detached);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.detached',
'boolean',
options.detached);
}

// Validate the uid, if present.
if (options.uid != null && !Number.isInteger(options.uid)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.uid', 'integer', options.uid);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.uid',
'integer',
options.uid);
}

// Validate the gid, if present.
if (options.gid != null && !Number.isInteger(options.gid)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.gid', 'integer', options.gid);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.gid',
'integer',
options.gid);
}

// Validate the shell, if present.
if (options.shell != null &&
typeof options.shell !== 'boolean' &&
typeof options.shell !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.shell', ['boolean', 'string'], options.shell);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.shell',
['boolean', 'string'],
options.shell);
}

// Validate argv0, if present.
if (options.argv0 != null &&
typeof options.argv0 !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.argv0', 'string', options.argv0);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.argv0',
'string',
options.argv0);
}

// Validate windowsHide, if present.
Expand All @@ -441,7 +468,10 @@ function normalizeSpawnArguments(file, args, options) {
// Validate windowsVerbatimArguments, if present.
if (options.windowsVerbatimArguments != null &&
typeof options.windowsVerbatimArguments !== 'boolean') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.windowsVerbatimArguments', 'boolean', options.windowsVerbatimArguments);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.windowsVerbatimArguments',
'boolean',
options.windowsVerbatimArguments);
}

// Make a shallow copy so we don't clobber the user's options object.
Expand Down Expand Up @@ -624,7 +654,9 @@ exports.execSync = execSync;
function validateTimeout(timeout) {
if (timeout != null && !(Number.isInteger(timeout) && timeout >= 0)) {
// TODO should this be a RangeError?
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'options.timeout', timeout);
throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'options.timeout',
timeout);
//"timeout" must be an unsigned integer');
}
}
Expand All @@ -633,7 +665,9 @@ function validateTimeout(timeout) {
function validateMaxBuffer(maxBuffer) {
if (maxBuffer != null && !(typeof maxBuffer === 'number' && maxBuffer >= 0)) {
// TODO should this be a RangeError?
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'options.maxBuffer', maxBuffer);
throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'options.maxBuffer',
maxBuffer);
//'"maxBuffer" must be a positive number');
}
}
Expand All @@ -643,6 +677,9 @@ function sanitizeKillSignal(killSignal) {
if (typeof killSignal === 'string' || typeof killSignal === 'number') {
return convertToValidSignal(killSignal);
} else if (killSignal != null) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.killSignal', ['string', 'number'], killSignal);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.killSignal',
['string', 'number'],
killSignal);
}
}
1 change: 0 additions & 1 deletion test/parallel/test-child-process-spawn-typeerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const { spawn, fork, execFile } = require('child_process');
const fixtures = require('../common/fixtures');
const cmd = common.isWindows ? 'rundll32' : 'ls';
const invalidcmd = 'hopefully_you_dont_have_this_on_your_machine';
const invalidOptionsMsg = /"options" argument must be an object/;

const empty = fixtures.path('empty.js');

Expand Down