summaryrefslogtreecommitdiff
path: root/lib/child_process.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2018-02-27 14:55:32 +0100
committerMichaël Zasso <targos@protonmail.com>2018-03-05 19:51:30 +0100
commit1e8d110e640c658e4f6ed7540db62d063269ba6c (patch)
treeafe2636b1b190fee00006beaa484fa77d5949770 /lib/child_process.js
parent023f49c5a938ef631260b76876155eaf957084be (diff)
downloadandroid-node-v8-1e8d110e640c658e4f6ed7540db62d063269ba6c.tar.gz
android-node-v8-1e8d110e640c658e4f6ed7540db62d063269ba6c.tar.bz2
android-node-v8-1e8d110e640c658e4f6ed7540db62d063269ba6c.zip
lib: port errors to new system
This is a first batch of updates that touches non-underscored modules in lib. PR-URL: https://github.com/nodejs/node/pull/19034 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'lib/child_process.js')
-rw-r--r--lib/child_process.js103
1 files changed, 40 insertions, 63 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index b190d9c70a..c18329554a 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -31,7 +31,14 @@ const { createPromise,
const debug = util.debuglog('child_process');
const { Buffer } = require('buffer');
const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap');
-const errors = require('internal/errors');
+const {
+ ERR_INVALID_ARG_VALUE,
+ ERR_CHILD_PROCESS_IPC_REQUIRED,
+ ERR_CHILD_PROCESS_STDIO_MAXBUFFER,
+ ERR_INVALID_ARG_TYPE,
+ ERR_INVALID_OPT_VALUE,
+ ERR_OUT_OF_RANGE
+} = require('internal/errors').codes;
const child_process = require('internal/child_process');
const {
_validateStdio,
@@ -48,7 +55,7 @@ function stdioStringToArray(option) {
case 'inherit':
return [option, option, option, 'ipc'];
default:
- throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'stdio', option);
+ throw new ERR_INVALID_OPT_VALUE('stdio', option);
}
}
@@ -65,9 +72,7 @@ exports.fork = function(modulePath /*, args, options*/) {
if (pos < arguments.length && arguments[pos] != null) {
if (typeof arguments[pos] !== 'object') {
- throw new errors.TypeError('ERR_INVALID_ARG_VALUE',
- `arguments[${pos}]`,
- arguments[pos]);
+ throw new ERR_INVALID_ARG_VALUE(`arguments[${pos}]`, arguments[pos]);
}
options = util._extend({}, arguments[pos++]);
@@ -95,8 +100,7 @@ exports.fork = function(modulePath /*, args, options*/) {
options.stdio = options.silent ? stdioStringToArray('pipe') :
stdioStringToArray('inherit');
} else if (options.stdio.indexOf('ipc') === -1) {
- throw new errors.Error('ERR_CHILD_PROCESS_IPC_REQUIRED',
- 'options.stdio');
+ throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
}
options.execPath = options.execPath || process.execPath;
@@ -200,7 +204,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
}
if (!callback && pos < arguments.length && arguments[pos] != null) {
- throw new errors.TypeError('ERR_INVALID_ARG_VALUE', 'args', arguments[pos]);
+ throw new ERR_INVALID_ARG_VALUE('args', arguments[pos]);
}
// Validate the timeout, if present.
@@ -327,8 +331,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
stdoutLen += encoding ? Buffer.byteLength(chunk, encoding) : chunk.length;
if (stdoutLen > options.maxBuffer) {
- ex = new errors.RangeError('ERR_CHILD_PROCESS_STDIO_MAXBUFFER',
- 'stdout');
+ ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stdout');
kill();
} else if (encoding) {
_stdout += chunk;
@@ -346,8 +349,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
stderrLen += encoding ? Buffer.byteLength(chunk, encoding) : chunk.length;
if (stderrLen > options.maxBuffer) {
- ex = new errors.RangeError('ERR_CHILD_PROCESS_STDIO_MAXBUFFER',
- 'stderr');
+ ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr');
kill();
} else if (encoding) {
_stderr += chunk;
@@ -384,13 +386,13 @@ function _convertCustomFds(options) {
function normalizeSpawnArguments(file, args, options) {
if (typeof file !== 'string' || file.length === 0)
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'file', 'string', file);
+ throw new ERR_INVALID_ARG_TYPE('file', 'string', file);
if (Array.isArray(args)) {
args = args.slice(0);
} else if (args !== undefined &&
(args === null || typeof args !== 'object')) {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'args', 'object', args);
+ throw new ERR_INVALID_ARG_TYPE('args', 'object', args);
} else {
options = args;
args = [];
@@ -399,77 +401,58 @@ 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 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 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 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 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 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 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 ERR_INVALID_ARG_TYPE('options.argv0', 'string', options.argv0);
}
// Validate windowsHide, if present.
if (options.windowsHide != null &&
typeof options.windowsHide !== 'boolean') {
- throw new TypeError('"windowsHide" must be a boolean');
+ throw new ERR_INVALID_ARG_TYPE('options.windowsHide',
+ 'boolean', options.windowsHide);
}
// 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 ERR_INVALID_ARG_TYPE('options.windowsVerbatimArguments',
+ 'boolean',
+ options.windowsVerbatimArguments);
}
// Make a shallow copy so we don't clobber the user's options object.
@@ -584,10 +567,9 @@ function spawnSync(/*file, args, options*/) {
} else if (typeof input === 'string') {
pipe.input = Buffer.from(input, options.encoding);
} else {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
- ('options.stdio[' + i + ']'),
- ['Buffer', 'Uint8Array', 'string'],
- input);
+ throw new ERR_INVALID_ARG_TYPE(`options.stdio[${i}]`,
+ ['Buffer', 'Uint8Array', 'string'],
+ input);
}
}
}
@@ -655,20 +637,16 @@ exports.execSync = execSync;
function validateTimeout(timeout) {
if (timeout != null && !(Number.isInteger(timeout) && timeout >= 0)) {
- throw new errors.RangeError('ERR_OUT_OF_RANGE',
- 'timeout',
- 'an unsigned integer',
- timeout);
+ throw new ERR_OUT_OF_RANGE('timeout', 'an unsigned integer', timeout);
}
}
function validateMaxBuffer(maxBuffer) {
if (maxBuffer != null && !(typeof maxBuffer === 'number' && maxBuffer >= 0)) {
- throw new errors.RangeError('ERR_OUT_OF_RANGE',
- 'options.maxBuffer',
- 'a positive number',
- maxBuffer);
+ throw new ERR_OUT_OF_RANGE('options.maxBuffer',
+ 'a positive number',
+ maxBuffer);
}
}
@@ -677,9 +655,8 @@ 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 ERR_INVALID_ARG_TYPE('options.killSignal',
+ ['string', 'number'],
+ killSignal);
}
}