lib: improve the usage of TypeError[INVALID_ARG_TYPE]

The initials of expected in TypeError[ERR_INVALID_ARG_TYPE]
are inconsistent. This change is to unify them.

PR-URL: https://github.com/nodejs/node/pull/16401
Fixes: https://github.com/nodejs/node/issues/16383
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Weijia Wang 2017-10-28 17:39:55 +08:00 committed by James M Snell
parent e0113ab5e0
commit e22b8d0c46
55 changed files with 96 additions and 96 deletions

View File

@ -105,7 +105,7 @@ function ClientRequest(options, cb) {
// when createConnection is provided. // when createConnection is provided.
} else if (typeof agent.addRequest !== 'function') { } else if (typeof agent.addRequest !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'Agent option', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'Agent option',
['Agent-like object', 'undefined', 'false']); ['Agent-like Object', 'undefined', 'false']);
} }
this.agent = agent; this.agent = agent;

View File

@ -650,7 +650,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
if (!fromEnd && typeof chunk !== 'string' && !(chunk instanceof Buffer)) { if (!fromEnd && typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
['string', 'buffer']); ['string', 'Buffer']);
} }
@ -748,7 +748,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
if (chunk) { if (chunk) {
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) { if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
['string', 'buffer']); ['string', 'Buffer']);
} }
if (!this._header) { if (!this._header) {
if (typeof chunk === 'string') if (typeof chunk === 'string')

View File

@ -846,7 +846,7 @@ function Server(options, listener) {
} else if (options == null || typeof options === 'object') { } else if (options == null || typeof options === 'object') {
options = options || {}; options = options || {};
} else { } else {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
} }

View File

@ -166,7 +166,7 @@ function innerThrows(shouldThrow, block, expected, message) {
var details = ''; var details = '';
if (typeof block !== 'function') { if (typeof block !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'function', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'Function',
block); block);
} }

View File

@ -199,7 +199,7 @@ Buffer.from = function from(value, encodingOrOffset, length) {
throw new errors.TypeError( throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'ERR_INVALID_ARG_TYPE',
'first argument', 'first argument',
['string', 'buffer', 'arrayBuffer', 'array', 'array-like object'], ['string', 'Buffer', 'ArrayBuffer', 'Array', 'Array-like Object'],
value value
); );
} }
@ -226,7 +226,7 @@ Buffer.from = function from(value, encodingOrOffset, length) {
throw new errors.TypeError( throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'ERR_INVALID_ARG_TYPE',
'first argument', 'first argument',
['string', 'buffer', 'arrayBuffer', 'array', 'array-like object'], ['string', 'Buffer', 'ArrayBuffer', 'Array', 'Array-like Object'],
value value
); );
}; };
@ -429,7 +429,7 @@ Buffer.isBuffer = function isBuffer(b) {
Buffer.compare = function compare(a, b) { Buffer.compare = function compare(a, b) {
if (!isUint8Array(a) || !isUint8Array(b)) { if (!isUint8Array(a) || !isUint8Array(b)) {
throw new errors.TypeError( throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', ['buf1', 'buf2'], ['buffer', 'uint8Array'] 'ERR_INVALID_ARG_TYPE', ['buf1', 'buf2'], ['Buffer', 'Uint8Array']
); );
} }
@ -448,7 +448,7 @@ Buffer.isEncoding = function isEncoding(encoding) {
Buffer[kIsEncodingSymbol] = Buffer.isEncoding; Buffer[kIsEncodingSymbol] = Buffer.isEncoding;
const kConcatErr = new errors.TypeError( const kConcatErr = new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'list', ['array', 'buffer', 'uint8Array'] 'ERR_INVALID_ARG_TYPE', 'list', ['Array', 'Buffer', 'Uint8Array']
); );
Buffer.concat = function concat(list, length) { Buffer.concat = function concat(list, length) {
@ -509,7 +509,7 @@ function byteLength(string, encoding) {
throw new errors.TypeError( throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'string', 'ERR_INVALID_ARG_TYPE', 'string',
['string', 'buffer', 'arrayBuffer'], string ['string', 'Buffer', 'ArrayBuffer'], string
); );
} }
@ -671,7 +671,7 @@ Buffer.prototype.equals = function equals(b) {
if (!isUint8Array(b)) { if (!isUint8Array(b)) {
throw new errors.TypeError( throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'otherBuffer', 'ERR_INVALID_ARG_TYPE', 'otherBuffer',
['buffer', 'uint8Array'], b ['Buffer', 'Uint8Array'], b
); );
} }
if (this === b) if (this === b)
@ -700,7 +700,7 @@ Buffer.prototype.compare = function compare(target,
if (!isUint8Array(target)) { if (!isUint8Array(target)) {
throw new errors.TypeError( throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'target', 'ERR_INVALID_ARG_TYPE', 'target',
['buffer', 'uint8Array'], target ['Buffer', 'Uint8Array'], target
); );
} }
if (arguments.length === 1) if (arguments.length === 1)
@ -783,7 +783,7 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
throw new errors.TypeError( throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'value', 'ERR_INVALID_ARG_TYPE', 'value',
['string', 'buffer', 'uint8Array'], val ['string', 'Buffer', 'Uint8Array'], val
); );
} }

View File

@ -63,7 +63,7 @@ function newHandle(type, lookup) {
if (lookup === undefined) if (lookup === undefined)
lookup = dns.lookup; lookup = dns.lookup;
else if (typeof lookup !== 'function') else if (typeof lookup !== 'function')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'lookup', 'function'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'lookup', 'Function');
if (type === 'udp4') { if (type === 'udp4') {
const handle = new UDP(); const handle = new UDP();

View File

@ -133,7 +133,7 @@ function lookup(hostname, options, callback) {
// Parse arguments // Parse arguments
if (hostname && typeof hostname !== 'string') { if (hostname && typeof hostname !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'hostname', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'hostname',
['string', 'falsey'], hostname); ['string', 'falsy'], hostname);
} else if (typeof options === 'function') { } else if (typeof options === 'function') {
callback = options; callback = options;
family = 0; family = 0;

View File

@ -243,7 +243,7 @@ function _addListener(target, type, listener, prepend) {
if (typeof listener !== 'function') { if (typeof listener !== 'function') {
const errors = lazyErrors(); const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'function'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'Function');
} }
events = target._events; events = target._events;
@ -344,7 +344,7 @@ function _onceWrap(target, type, listener) {
EventEmitter.prototype.once = function once(type, listener) { EventEmitter.prototype.once = function once(type, listener) {
if (typeof listener !== 'function') { if (typeof listener !== 'function') {
const errors = lazyErrors(); const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'function'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'Function');
} }
this.on(type, _onceWrap(this, type, listener)); this.on(type, _onceWrap(this, type, listener));
return this; return this;
@ -355,7 +355,7 @@ EventEmitter.prototype.prependOnceListener =
if (typeof listener !== 'function') { if (typeof listener !== 'function') {
const errors = lazyErrors(); const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener',
'function'); 'Function');
} }
this.prependListener(type, _onceWrap(this, type, listener)); this.prependListener(type, _onceWrap(this, type, listener));
return this; return this;
@ -369,7 +369,7 @@ EventEmitter.prototype.removeListener =
if (typeof listener !== 'function') { if (typeof listener !== 'function') {
const errors = lazyErrors(); const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener',
'function'); 'Function');
} }
events = this._events; events = this._events;

View File

@ -86,7 +86,7 @@ function getOptions(options, defaultOptions) {
} else if (typeof options !== 'object') { } else if (typeof options !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options', 'options',
['string', 'object'], ['string', 'Object'],
options); options);
} }
@ -1209,7 +1209,7 @@ function toUnixTimestamp(time) {
} }
throw new errors.Error('ERR_INVALID_ARG_TYPE', throw new errors.Error('ERR_INVALID_ARG_TYPE',
'time', 'time',
['Date', 'time in seconds'], ['Date', 'Time in seconds'],
time); time);
} }
@ -1513,7 +1513,7 @@ fs.watchFile = function(filename, options, listener) {
if (typeof listener !== 'function') { if (typeof listener !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'listener', 'listener',
'function', 'Function',
listener); listener);
} }
@ -1922,7 +1922,7 @@ fs.copyFile = function(src, dest, flags, callback) {
callback = flags; callback = flags;
flags = 0; flags = 0;
} else if (typeof callback !== 'function') { } else if (typeof callback !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'callback', 'function'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'callback', 'Function');
} }
src = getPathFromURL(src); src = getPathFromURL(src);

View File

@ -56,7 +56,7 @@ class Session extends EventEmitter {
} }
if (params && typeof params !== 'object') { if (params && typeof params !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'params', 'object', params); 'params', 'Object', params);
} }
if (callback && typeof callback !== 'function') { if (callback && typeof callback !== 'function') {
throw new errors.TypeError('ERR_INVALID_CALLBACK'); throw new errors.TypeError('ERR_INVALID_CALLBACK');

View File

@ -273,7 +273,7 @@ ChildProcess.prototype.spawn = function(options) {
var i; var i;
if (options === null || typeof options !== 'object') { if (options === null || typeof options !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object',
options); options);
} }
@ -594,7 +594,7 @@ function setupChannel(target, channel) {
options = undefined; options = undefined;
} else if (options !== undefined && } else if (options !== undefined &&
(options === null || typeof options !== 'object')) { (options === null || typeof options !== 'object')) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object',
options); options);
} }

View File

@ -345,7 +345,7 @@ function makeTextDecoderICU() {
constructor(encoding = 'utf-8', options = {}) { constructor(encoding = 'utf-8', options = {}) {
encoding = `${encoding}`; encoding = `${encoding}`;
if (typeof options !== 'object') if (typeof options !== 'object')
throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'object'); throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'Object');
const enc = getEncodingFromLabel(encoding); const enc = getEncodingFromLabel(encoding);
if (enc === undefined) if (enc === undefined)
@ -378,7 +378,7 @@ function makeTextDecoderICU() {
['ArrayBuffer', 'ArrayBufferView']); ['ArrayBuffer', 'ArrayBufferView']);
} }
if (typeof options !== 'object') { if (typeof options !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
} }
var flags = 0; var flags = 0;
@ -417,7 +417,7 @@ function makeTextDecoderJS() {
constructor(encoding = 'utf-8', options = {}) { constructor(encoding = 'utf-8', options = {}) {
encoding = `${encoding}`; encoding = `${encoding}`;
if (typeof options !== 'object') if (typeof options !== 'object')
throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'object'); throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'Object');
const enc = getEncodingFromLabel(encoding); const enc = getEncodingFromLabel(encoding);
if (enc === undefined || !hasConverter(enc)) if (enc === undefined || !hasConverter(enc))
@ -452,7 +452,7 @@ function makeTextDecoderJS() {
['ArrayBuffer', 'ArrayBufferView']); ['ArrayBuffer', 'ArrayBufferView']);
} }
if (typeof options !== 'object') { if (typeof options !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
} }
if (this[kFlags] & CONVERTER_FLAGS_FLUSH) { if (this[kFlags] & CONVERTER_FLAGS_FLUSH) {

View File

@ -133,7 +133,7 @@ class SystemError extends makeNodeError(Error) {
class AssertionError extends Error { class AssertionError extends Error {
constructor(options) { constructor(options) {
if (typeof options !== 'object' || options === null) { if (typeof options !== 'object' || options === null) {
throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object'); throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
} }
var { actual, expected, message, operator, stackStartFunction } = options; var { actual, expected, message, operator, stackStartFunction } = options;
if (message) { if (message) {

View File

@ -2484,7 +2484,7 @@ function connect(authority, options, listener) {
if (typeof authority === 'string') if (typeof authority === 'string')
authority = new URL(authority); authority = new URL(authority);
assertIsObject(authority, 'authority', ['string', 'object', 'URL']); assertIsObject(authority, 'authority', ['string', 'Object', 'URL']);
debug(`connecting to ${authority}`); debug(`connecting to ${authority}`);
@ -2539,7 +2539,7 @@ function createSecureServer(options, handler) {
if (options == null || typeof options !== 'object') { if (options == null || typeof options !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options', 'options',
'object'); 'Object');
} }
debug('creating http2secureserver'); debug('creating http2secureserver');
return new Http2SecureServer(options, handler); return new Http2SecureServer(options, handler);

View File

@ -465,7 +465,7 @@ class NghttpError extends Error {
} }
} }
function assertIsObject(value, name, types = 'object') { function assertIsObject(value, name, types = 'Object') {
if (value !== undefined && if (value !== undefined &&
(value === null || (value === null ||
typeof value !== 'object' || typeof value !== 'object' ||

View File

@ -28,12 +28,12 @@ function setup_cpuUsage() {
if (prevValue) { if (prevValue) {
if (!previousValueIsValid(prevValue.user)) { if (!previousValueIsValid(prevValue.user)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'preValue.user', 'Number'); 'preValue.user', 'number');
} }
if (!previousValueIsValid(prevValue.system)) { if (!previousValueIsValid(prevValue.system)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'preValue.system', 'Number'); 'preValue.system', 'number');
} }
} }
@ -154,7 +154,7 @@ function setupKillAndExit() {
// eslint-disable-next-line eqeqeq // eslint-disable-next-line eqeqeq
if (pid != (pid | 0)) { if (pid != (pid | 0)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pid', 'Number'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pid', 'number');
} }
// preserve null signal // preserve null signal

View File

@ -372,7 +372,7 @@ Object.defineProperties(URL.prototype, {
// eslint-disable-next-line func-name-matching // eslint-disable-next-line func-name-matching
value: function format(options) { value: function format(options) {
if (options && typeof options !== 'object') if (options && typeof options !== 'object')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
options = util._extend({ options = util._extend({
fragment: true, fragment: true,
unicode: false, unicode: false,

View File

@ -208,14 +208,14 @@ const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs');
function promisify(original) { function promisify(original) {
if (typeof original !== 'function') if (typeof original !== 'function')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'function'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'Function');
if (original[kCustomPromisifiedSymbol]) { if (original[kCustomPromisifiedSymbol]) {
const fn = original[kCustomPromisifiedSymbol]; const fn = original[kCustomPromisifiedSymbol];
if (typeof fn !== 'function') { if (typeof fn !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'util.promisify.custom', 'util.promisify.custom',
'function', 'Function',
fn); fn);
} }
Object.defineProperty(fn, kCustomPromisifiedSymbol, { Object.defineProperty(fn, kCustomPromisifiedSymbol, {

View File

@ -1080,7 +1080,7 @@ function lookupAndConnect(self, options) {
if (options.lookup && typeof options.lookup !== 'function') if (options.lookup && typeof options.lookup !== 'function')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options.lookup', 'options.lookup',
'function', 'Function',
options.lookup); options.lookup);
var dnsopts = { var dnsopts = {
@ -1225,7 +1225,7 @@ function Server(options, connectionListener) {
} else { } else {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'options', 'options',
'object', 'Object',
options); options);
} }

View File

@ -1111,7 +1111,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
} else if (typeof cmd.action !== 'function') { } else if (typeof cmd.action !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'action', 'action',
'function', 'Function',
cmd.action); cmd.action);
} }
this.commands[keyword] = cmd; this.commands[keyword] = cmd;

View File

@ -556,7 +556,7 @@ function urlFormat(urlObject, options) {
urlObject = urlParse(urlObject); urlObject = urlParse(urlObject);
} else if (typeof urlObject !== 'object' || urlObject === null) { } else if (typeof urlObject !== 'object' || urlObject === null) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObject', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObject',
['object', 'string'], urlObject); ['Object', 'string'], urlObject);
} else if (!(urlObject instanceof Url)) { } else if (!(urlObject instanceof Url)) {
var format = urlObject[formatSymbol]; var format = urlObject[formatSymbol];
return format ? return format ?

View File

@ -335,7 +335,7 @@ Object.defineProperty(inspect, 'defaultOptions', {
}, },
set(options) { set(options) {
if (options === null || typeof options !== 'object') { if (options === null || typeof options !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
} }
Object.assign(inspectDefaultOptions, options); Object.assign(inspectDefaultOptions, options);
return inspectDefaultOptions; return inspectDefaultOptions;
@ -970,14 +970,14 @@ function log() {
function inherits(ctor, superCtor) { function inherits(ctor, superCtor) {
if (ctor === undefined || ctor === null) if (ctor === undefined || ctor === null)
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ctor', 'function'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ctor', 'Function');
if (superCtor === undefined || superCtor === null) if (superCtor === undefined || superCtor === null)
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'function'); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'Function');
if (superCtor.prototype === undefined) { if (superCtor.prototype === undefined) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor.prototype', throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor.prototype',
'function'); 'Function');
} }
ctor.super_ = superCtor; ctor.super_ = superCtor;
Object.setPrototypeOf(ctor.prototype, superCtor.prototype); Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
@ -1080,7 +1080,7 @@ function callbackify(original) {
throw new errors.TypeError( throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'ERR_INVALID_ARG_TYPE',
'original', 'original',
'function'); 'Function');
} }
// We DO NOT return the promise as it gives the user a false sense that // We DO NOT return the promise as it gives the user a false sense that
@ -1092,7 +1092,7 @@ function callbackify(original) {
throw new errors.TypeError( throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE', 'ERR_INVALID_ARG_TYPE',
'last argument', 'last argument',
'function'); 'Function');
} }
const cb = (...args) => { Reflect.apply(maybeCb, this, args); }; const cb = (...args) => { Reflect.apply(maybeCb, this, args); };
// In true node style we process the callback on `nextTick` with all the // In true node style we process the callback on `nextTick` with all the

View File

@ -689,8 +689,8 @@ try {
common.expectsError({ common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "block" argument must be of type function. Received ' + message: 'The "block" argument must be of type Function. Received ' +
`type ${typeName(block)}` 'type ' + typeName(block)
})(e); })(e);
} }
@ -732,7 +732,7 @@ assert.throws(() => {
{ {
// bad args to AssertionError constructor should throw TypeError // bad args to AssertionError constructor should throw TypeError
const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined]; const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined];
const re = /^The "options" argument must be of type object$/; const re = /^The "options" argument must be of type Object$/;
args.forEach((input) => { args.forEach((input) => {
assert.throws( assert.throws(
() => new assert.AssertionError(input), () => new assert.AssertionError(input),

View File

@ -934,8 +934,8 @@ assert.throws(() => Buffer.allocUnsafe(10).copy(),
/TypeError: argument should be a Buffer/); /TypeError: argument should be a Buffer/);
const regErrorMsg = const regErrorMsg =
new RegExp('The first argument must be one of type string, buffer, ' + new RegExp('The first argument must be one of type string, Buffer, ' +
'arrayBuffer, array, or array-like object\\.'); 'ArrayBuffer, Array, or Array-like Object\\.');
assert.throws(() => Buffer.from(), regErrorMsg); assert.throws(() => Buffer.from(), regErrorMsg);
assert.throws(() => Buffer.from(null), regErrorMsg); assert.throws(() => Buffer.from(null), regErrorMsg);

View File

@ -17,7 +17,7 @@ const vm = require('vm');
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "string" argument must be one of type string, ' + message: 'The "string" argument must be one of type string, ' +
`buffer, or arrayBuffer. Received type ${typeof args[0]}` `Buffer, or ArrayBuffer. Received type ${typeof args[0]}`
} }
); );
}); });

View File

@ -70,5 +70,5 @@ assert.throws(() => a.compare(), common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "target" argument must be one of ' + message: 'The "target" argument must be one of ' +
'type buffer or uint8Array. Received type undefined' 'type Buffer or Uint8Array. Received type undefined'
})); }));

View File

@ -32,7 +32,7 @@ const errMsg = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "buf1", "buf2" arguments must be one of ' + message: 'The "buf1", "buf2" arguments must be one of ' +
'type buffer or uint8Array' 'type Buffer or Uint8Array'
}, 2); }, 2);
assert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'), errMsg); assert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'), errMsg);
@ -42,5 +42,5 @@ assert.throws(() => Buffer.alloc(1).compare('abc'), common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "target" argument must be one of ' + message: 'The "target" argument must be one of ' +
'type buffer or uint8Array. Received type string' 'type Buffer or Uint8Array. Received type string'
})); }));

View File

@ -58,7 +58,7 @@ function assertWrongList(value) {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "list" argument must be one of type ' + message: 'The "list" argument must be one of type ' +
'array, buffer, or uint8Array' 'Array, Buffer, or Uint8Array'
})); }));
} }

View File

@ -20,6 +20,6 @@ common.expectsError(
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "otherBuffer" argument must be one of type ' + message: 'The "otherBuffer" argument must be one of type ' +
'buffer or uint8Array. Received type string' 'Buffer or Uint8Array. Received type string'
} }
); );

View File

@ -46,8 +46,8 @@ deepStrictEqual(
const err = common.expectsError({ const err = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The first argument must be one of type string, buffer, ' + message: 'The first argument must be one of type string, Buffer, ' +
'arrayBuffer, array, or array-like object. Received ' + 'ArrayBuffer, Array, or Array-like Object. Received ' +
`type ${actualType}` `type ${actualType}`
}); });
throws(() => Buffer.from(input), err); throws(() => Buffer.from(input), err);

View File

@ -282,7 +282,7 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "value" argument must be one of type string, ' + message: 'The "value" argument must be one of type string, ' +
`buffer, or uint8Array. Received type ${typeof val}` `Buffer, or Uint8Array. Received type ${typeof val}`
} }
); );
}); });

View File

@ -357,7 +357,7 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1);
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "value" argument must be one of type string, ' + message: 'The "value" argument must be one of type string, ' +
`buffer, or uint8Array. Received type ${typeof val}` `Buffer, or Uint8Array. Received type ${typeof val}`
} }
); );
}); });

View File

@ -19,7 +19,7 @@ function typeName(value) {
}, { }, {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "options" argument must be of type object. ' + message: 'The "options" argument must be of type Object. ' +
`Received type ${typeName(options)}` `Received type ${typeName(options)}`
}); });
}); });

View File

@ -41,7 +41,7 @@ const dns = require('dns');
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "lookup" argument must be of type function' message: 'The "lookup" argument must be of type Function'
})); }));
}); });
} }

View File

@ -12,7 +12,7 @@ assert.throws(() => {
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: /^The "hostname" argument must be one of type string or falsey/ message: /^The "hostname" argument must be one of type string or falsy/
})); }));
assert.throws(() => { assert.throws(() => {

View File

@ -123,7 +123,7 @@ assert.throws(() => {
const errorReg = common.expectsError({ const errorReg = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: /^The "hostname" argument must be one of type string or falsey/ message: /^The "hostname" argument must be one of type string or falsy/
}, 5); }, 5);
assert.throws(() => dns.lookup({}, common.mustNotCall()), errorReg); assert.throws(() => dns.lookup({}, common.mustNotCall()), errorReg);

View File

@ -92,5 +92,5 @@ common.expectsError(() => {
}, { }, {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "listener" argument must be of type function' message: 'The "listener" argument must be of type Function'
}); });

View File

@ -57,7 +57,7 @@ common.expectsError(() => {
}, { }, {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "listener" argument must be of type function' message: 'The "listener" argument must be of type Function'
}); });
{ {

View File

@ -26,7 +26,7 @@ common.expectsError(() => {
}, { }, {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "listener" argument must be of type function' message: 'The "listener" argument must be of type Function'
}); });
// Test fallback if prependListener is undefined. // Test fallback if prependListener is undefined.

View File

@ -151,7 +151,7 @@ common.expectsError(() => {
}, { }, {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "listener" argument must be of type function' message: 'The "listener" argument must be of type Function'
}); });
{ {

View File

@ -66,7 +66,7 @@ common.expectsError(() => {
}, { }, {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "callback" argument must be of type function' message: 'The "callback" argument must be of type Function'
}); });
// Throws if the source path is not a string. // Throws if the source path is not a string.

View File

@ -53,7 +53,7 @@ server.listen(0, baseOptions.host, common.mustCall(function() {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "Agent option" argument must be one of type ' + message: 'The "Agent option" argument must be one of type ' +
'Agent-like object, undefined, or false' 'Agent-like Object, undefined, or false'
}) })
); );
}); });

View File

@ -84,7 +84,7 @@ assert.throws(() => {
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The first argument must be one of type string or buffer' message: 'The first argument must be one of type string or Buffer'
})); }));
assert.throws(() => { assert.throws(() => {
@ -93,7 +93,7 @@ assert.throws(() => {
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The first argument must be one of type string or buffer' message: 'The first argument must be one of type string or Buffer'
})); }));
// addTrailers() // addTrailers()

View File

@ -10,7 +10,7 @@ const invalidOptions = [() => {}, 1, 'test', null, undefined];
const invalidArgTypeError = { const invalidArgTypeError = {
type: TypeError, type: TypeError,
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type object' message: 'The "options" argument must be of type Object'
}; };
// Error if options are not passed to createSecureServer // Error if options are not passed to createSecureServer

View File

@ -35,7 +35,7 @@ common.expectsError(
{ {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "test" argument must be of type object' message: 'The "test" argument must be of type Object'
}); });
common.expectsError( common.expectsError(

View File

@ -15,7 +15,7 @@ const {
new Date(), new Date(),
new (class Foo {})() new (class Foo {})()
].forEach((i) => { ].forEach((i) => {
assert.doesNotThrow(() => assertIsObject(i, 'foo', 'object')); assert.doesNotThrow(() => assertIsObject(i, 'foo', 'Object'));
}); });
[ [
@ -27,10 +27,10 @@ const {
[], [],
[{}] [{}]
].forEach((i) => { ].forEach((i) => {
assert.throws(() => assertIsObject(i, 'foo', 'object'), assert.throws(() => assertIsObject(i, 'foo', 'Object'),
common.expectsError({ common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: /^The "foo" argument must be of type object$/ message: /^The "foo" argument must be of type Object$/
})); }));
}); });

View File

@ -34,13 +34,13 @@ for (let i = 0; i < 10; i++) {
const invalidUserArgument = common.expectsError({ const invalidUserArgument = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "preValue.user" property must be of type Number' message: 'The "preValue.user" property must be of type number'
}, 8); }, 8);
const invalidSystemArgument = common.expectsError({ const invalidSystemArgument = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "preValue.system" property must be of type Number' message: 'The "preValue.system" property must be of type number'
}, 2); }, 2);

View File

@ -41,7 +41,7 @@ const assert = require('assert');
const invalidPidArgument = common.expectsError({ const invalidPidArgument = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "pid" argument must be of type Number' message: 'The "pid" argument must be of type number'
}, 6); }, 6);
assert.throws(function() { process.kill('SIGTERM'); }, assert.throws(function() { process.kill('SIGTERM'); },

View File

@ -43,7 +43,7 @@ assert.throws(() => tls.createServer('this is not valid'),
common.expectsError({ common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "options" argument must be of type object' message: 'The "options" argument must be of type Object'
}) })
); );

View File

@ -17,7 +17,7 @@ for (const [urlObject, type] of throwsObjsAndReportTypes) {
const error = common.expectsError({ const error = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "urlObject" argument must be one of type object or string. ' + message: 'The "urlObject" argument must be one of type Object or string. ' +
`Received type ${type}` `Received type ${type}`
}); });
assert.throws(function() { url.format(urlObject); }, error); assert.throws(function() { url.format(urlObject); }, error);

View File

@ -24,7 +24,7 @@ assert.strictEqual(
const expectedErr = common.expectsError({ const expectedErr = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "options" argument must be of type object' message: 'The "options" argument must be of type Object'
}, 4); }, 4);
assert.throws(() => url.format(myURL, true), expectedErr); assert.throws(() => url.format(myURL, true), expectedErr);
assert.throws(() => url.format(myURL, 1), expectedErr); assert.throws(() => url.format(myURL, 1), expectedErr);

View File

@ -234,7 +234,7 @@ const values = [
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "original" argument must be of type function' message: 'The "original" argument must be of type Function'
})); }));
}); });
} }
@ -255,7 +255,7 @@ const values = [
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The last argument must be of type function' message: 'The last argument must be of type Function'
})); }));
}); });
} }

View File

@ -6,7 +6,7 @@ const inherits = require('util').inherits;
const errCheck = common.expectsError({ const errCheck = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "superCtor" argument must be of type function' message: 'The "superCtor" argument must be of type Function'
}); });
// super constructor // super constructor
@ -85,7 +85,7 @@ assert.throws(function() {
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "superCtor.prototype" property must be of type function' message: 'The "superCtor.prototype" property must be of type Function'
}) })
); );
assert.throws(function() { assert.throws(function() {
@ -96,6 +96,6 @@ assert.throws(function() {
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "ctor" argument must be of type function' message: 'The "ctor" argument must be of type Function'
}) })
); );

View File

@ -1136,7 +1136,7 @@ if (typeof Symbol !== 'undefined') {
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "options" argument must be of type object' message: 'The "options" argument must be of type Object'
}) })
); );
@ -1145,7 +1145,7 @@ if (typeof Symbol !== 'undefined') {
}, common.expectsError({ }, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "options" argument must be of type object' message: 'The "options" argument must be of type Object'
}) })
); );
} }

View File

@ -43,7 +43,7 @@ assert.doesNotThrow(
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: message:
'The "params" argument must be of type object. ' + 'The "params" argument must be of type Object. ' +
`Received type ${typeof i}` `Received type ${typeof i}`
} }
); );