diff --git a/lib/dgram.js b/lib/dgram.js index 3204ad87cd5cd9..abfcd57a0c1b57 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -262,19 +262,22 @@ Socket.prototype.sendto = function(buffer, address, callback) { if (typeof offset !== 'number') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'offset', 'number'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'offset', 'number', + offset); } if (typeof length !== 'number') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'length', 'number'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'length', 'number', + length); } if (typeof port !== 'number') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'port', 'number'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'port', 'number', port); } if (typeof address !== 'string') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'address', 'string'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'address', 'string', + address); } this.send(buffer, offset, length, port, address, callback); @@ -287,7 +290,8 @@ function sliceBuffer(buffer, offset, length) { } else if (!isUint8Array(buffer)) { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'buffer', - ['Buffer', 'Uint8Array', 'string']); + ['Buffer', 'Uint8Array', 'string'], + buffer); } offset = offset >>> 0; @@ -380,14 +384,16 @@ Socket.prototype.send = function(buffer, } else if (!isUint8Array(buffer)) { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'buffer', - ['Buffer', 'Uint8Array', 'string']); + ['Buffer', 'Uint8Array', 'string'], + buffer); } else { list = [ buffer ]; } } else if (!(list = fixBufferList(buffer))) { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'buffer list arguments', - ['Buffer', 'string']); + ['Buffer', 'string'], + buffer); } port = port >>> 0; @@ -405,7 +411,8 @@ Socket.prototype.send = function(buffer, } else if (address && typeof address !== 'string') { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'address', - ['string', 'falsy']); + ['string', 'falsy'], + address); } this._healthCheck(); diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 216a2fb85a0efe..5afb01b652e4c4 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -284,7 +284,7 @@ ChildProcess.prototype.spawn = function(options) { options.envPairs = []; else if (!Array.isArray(options.envPairs)) { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.envPairs', - 'array', options.envPairs); + 'Array', options.envPairs); } options.envPairs.push('NODE_CHANNEL_FD=' + ipcFd); @@ -301,7 +301,7 @@ ChildProcess.prototype.spawn = function(options) { else if (options.args === undefined) this.spawnargs = []; else - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.args', 'array', + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.args', 'Array', options.args); var err = this._handle.spawn(options); diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 47871cfe463360..e9d0c101224e47 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -43,7 +43,8 @@ function makeNodeError(Base) { class AssertionError extends Error { constructor(options) { 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', + options); } const util = lazyUtil(); const message = options.message || @@ -150,7 +151,7 @@ E('ERR_INVALID_URL', 'Invalid URL: %s'); E('ERR_INVALID_URL_SCHEME', (expected) => { lazyAssert(); - return `The URL must be ${oneOf(expected, 'scheme')}`; + return `The URL must be ${oneOf(expected, 'of scheme')}`; }); E('ERR_IPC_CHANNEL_CLOSED', 'Channel closed'); E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected'); @@ -183,12 +184,26 @@ E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' + function invalidArgType(name, expected, actual) { const assert = lazyAssert(); assert(name, 'name is required'); - const type = name.includes('.') ? 'property' : 'argument'; - var msg = `The "${name}" ${type} must be ${oneOf(expected, 'type')}`; - if (arguments.length >= 3) { - msg += `. Received type ${actual !== null ? typeof actual : 'null'}`; + assert.strictEqual(arguments.length, 3, 'arguments length mismatch'); + const argType = name.includes('.') ? 'property' : 'argument'; + // Only check the first entry + const expectedType = Array.isArray(expected) ? expected[0] : expected; + // A-Z = 65-90, a-z = 97-122 + const type = expectedType.charCodeAt(0) > 96 ? 'of type' : 'instance of'; + var received; + if (actual == null) { + received = String(actual); + } else if (typeof actual === 'object') { + if (actual.constructor != null) { + received = `instance of ${actual.constructor.name}`; + } else { + received = 'a plain object'; + } + } else { + received = `type ${typeof actual}`; } - return msg; + return `The "${name}" ${argType} must be ${oneOf(expected, type)}. ` + + `Received ${received}`; } function missingArgs(...args) { @@ -220,14 +235,14 @@ function oneOf(expected, thing) { assert(len > 0, 'At least one expected value needs to be specified'); expected = expected.map((i) => String(i)); if (len > 2) { - return `one of ${thing} ${expected.slice(0, len - 1).join(', ')}, or ` + + return `${thing} ${expected.slice(0, len - 1).join(', ')}, or ` + expected[len - 1]; } else if (len === 2) { - return `one of ${thing} ${expected[0]} or ${expected[1]}`; + return `${thing} ${expected[0]} or ${expected[1]}`; } else { - return `of ${thing} ${expected[0]}`; + return `${thing} ${expected[0]}`; } } else { - return `of ${thing} ${String(expected)}`; + return `${thing} ${String(expected)}`; } } diff --git a/lib/internal/process.js b/lib/internal/process.js index bb9117ea09de50..c45315d3bdf141 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -30,12 +30,14 @@ function setup_cpuUsage() { if (prevValue) { if (!previousValueIsValid(prevValue.user)) { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', - 'preValue.user', 'Number'); + 'prevValue.user', 'number', prevValue.user); } if (!previousValueIsValid(prevValue.system)) { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', - 'preValue.system', 'Number'); + 'prevValue.system', + 'number', + prevValue.system); } } @@ -170,7 +172,7 @@ function setupKillAndExit() { // eslint-disable-next-line eqeqeq if (pid != (pid | 0)) { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pid', 'Number'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pid', 'number', pid); } // preserve null signal diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 3208fb098d0a97..82c6e994cb258d 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -130,9 +130,11 @@ function setupProcessWarnings() { code = undefined; } if (code !== undefined && typeof code !== 'string') - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'code', 'string'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'code', 'string', + code); if (type !== undefined && typeof type !== 'string') - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'type', 'string'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'type', 'string', + type); if (warning === undefined || typeof warning === 'string') { warning = new Error(warning); warning.name = String(type || 'Warning'); @@ -142,7 +144,9 @@ function setupProcessWarnings() { } if (!(warning instanceof Error)) { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', - 'warning', ['Error', 'string']); + 'warning', + ['Error', 'of type string'], + warning); } if (warning.name === 'DeprecationWarning') { if (process.noDeprecation) diff --git a/lib/internal/url.js b/lib/internal/url.js index 6048777cfd23a5..107312d50b30d1 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -372,7 +372,8 @@ Object.defineProperties(URL.prototype, { // eslint-disable-next-line func-name-matching value: function format(options) { 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); options = Object.assign({ fragment: true, unicode: false, diff --git a/lib/internal/util.js b/lib/internal/util.js index 543ebbaf6d6fa6..b66a8362bc87ff 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -34,7 +34,7 @@ function deprecate(fn, msg, code) { } if (code !== undefined && typeof code !== 'string') - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'code', 'string'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'code', 'string', code); var warned = false; function deprecated(...args) { @@ -204,7 +204,8 @@ const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs'); function promisify(orig) { if (typeof orig !== 'function') { const errors = require('internal/errors'); - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'function'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'function', + orig); } if (orig[kCustomPromisifiedSymbol]) { diff --git a/lib/path.js b/lib/path.js index 001152866ffc35..90f73a6f7c2809 100644 --- a/lib/path.js +++ b/lib/path.js @@ -25,7 +25,7 @@ const errors = require('internal/errors'); function assertPath(path) { if (typeof path !== 'string') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path', 'string'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path', 'string', path); } } @@ -816,7 +816,7 @@ const win32 = { basename: function basename(path, ext) { if (ext !== undefined && typeof ext !== 'string') - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ext', 'string'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ext', 'string', ext); assertPath(path); var start = 0; var end = -1; @@ -959,7 +959,7 @@ const win32 = { format: function format(pathObject) { if (pathObject === null || typeof pathObject !== 'object') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object', + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'object', pathObject); } return _format('\\', pathObject); @@ -1371,7 +1371,7 @@ const posix = { basename: function basename(path, ext) { if (ext !== undefined && typeof ext !== 'string') - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ext', 'string'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ext', 'string', ext); assertPath(path); var start = 0; @@ -1502,7 +1502,7 @@ const posix = { format: function format(pathObject) { if (pathObject === null || typeof pathObject !== 'object') { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object', + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'object', pathObject); } return _format('/', pathObject); diff --git a/lib/repl.js b/lib/repl.js index 9954a300d70641..d26eabfd154c3f 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1052,7 +1052,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) { cmd = {action: cmd}; } else if (typeof cmd.action !== 'function') { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', - 'action', 'function', cmd.action); + 'cmd.action', 'function', cmd.action); } this.commands[keyword] = cmd; }; diff --git a/lib/util.js b/lib/util.js index fea6471de6260b..8d20d058768731 100644 --- a/lib/util.js +++ b/lib/util.js @@ -205,7 +205,11 @@ Object.defineProperty(inspect, 'defaultOptions', { }, set: function(options) { 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); } Object.assign(inspectDefaultOptions, options); return inspectDefaultOptions; @@ -957,14 +961,18 @@ exports.log = function() { exports.inherits = function(ctor, superCtor) { 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', + ctor); 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', + superCtor); if (superCtor.prototype === undefined) { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor.prototype', - 'function'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', + 'superCtor.prototype', + 'function', + superCtor.prototype); } ctor.super_ = superCtor; Object.setPrototypeOf(ctor.prototype, superCtor.prototype); @@ -1077,7 +1085,8 @@ function callbackify(original) { throw new errors.TypeError( 'ERR_INVALID_ARG_TYPE', 'original', - 'function'); + 'function', + original); } // We DO NOT return the promise as it gives the user a false sense that @@ -1089,7 +1098,8 @@ function callbackify(original) { throw new errors.TypeError( 'ERR_INVALID_ARG_TYPE', 'last argument', - 'function'); + 'function', + maybeCb); } const cb = (...args) => { Reflect.apply(maybeCb, this, args); }; // In true node style we process the callback on `nextTick` with all the diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index d4a1b277bcc195..854924bf461ee8 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -676,7 +676,14 @@ try { { // Verify that throws() and doesNotThrow() throw on non-function block function typeName(value) { - return value === null ? 'null' : typeof value; + if (value == null) { + return value; + } + const type = typeof value; + if (type !== 'object') { + return `type ${type}`; + } + return `instance of ${value.constructor.name}`; } const testBlockTypeError = (method, block) => { @@ -690,7 +697,7 @@ try { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "block" argument must be of type function. Received ' + - 'type ' + typeName(block) + typeName(block) })(e); } @@ -732,7 +739,7 @@ assert.throws(() => { { // bad args to AssertionError constructor should throw TypeError 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\. Received /; args.forEach((input) => { assert.throws( () => new assert.AssertionError(input), diff --git a/test/parallel/test-child-process-constructor.js b/test/parallel/test-child-process-constructor.js index ea81f806060cb6..b11f9e900cd6fc 100644 --- a/test/parallel/test-child-process-constructor.js +++ b/test/parallel/test-child-process-constructor.js @@ -6,7 +6,14 @@ const { ChildProcess } = require('child_process'); assert.strictEqual(typeof ChildProcess, 'function'); function typeName(value) { - return value === null ? 'null' : typeof value; + if (value == null) { + return value; + } + const type = typeof value; + if (type !== 'object') { + return `type ${type}`; + } + return `instance of ${value.constructor.name}`; } { @@ -19,7 +26,7 @@ function typeName(value) { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type object. Received type ' + + message: 'The "options" argument must be of type object. Received ' + typeName(options) })); }); @@ -36,7 +43,7 @@ function typeName(value) { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.file" property must be of type string. Received ' + - 'type ' + typeName(file) + typeName(file) })); }); } @@ -51,8 +58,8 @@ function typeName(value) { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.envPairs" property must be of type array. ' + - 'Received type ' + typeName(envPairs) + message: 'The "options.envPairs" property must be instance of Array. ' + + 'Received ' + typeName(envPairs) })); }); } @@ -67,8 +74,8 @@ function typeName(value) { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.args" property must be of type array. Received ' + - 'type ' + typeName(args) + message: 'The "options.args" property must be instance of Array. ' + + 'Received ' + typeName(args) })); }); } diff --git a/test/parallel/test-dgram-send-address-types.js b/test/parallel/test-dgram-send-address-types.js index 6b26c23a266558..5bc8a0fb98a593 100644 --- a/test/parallel/test-dgram-send-address-types.js +++ b/test/parallel/test-dgram-send-address-types.js @@ -13,7 +13,7 @@ const onMessage = common.mustCall((err, bytes) => { const expectedError = { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - /^The "address" argument must be one of type string or falsy$/ + /^The "address" argument must be of type string or falsy\. Received / }; const client = dgram.createSocket('udp4').bind(0, () => { diff --git a/test/parallel/test-dgram-sendto.js b/test/parallel/test-dgram-sendto.js index c922dc1039e732..7866e1b1068d15 100644 --- a/test/parallel/test-dgram-sendto.js +++ b/test/parallel/test-dgram-sendto.js @@ -5,7 +5,7 @@ const dgram = require('dgram'); const socket = dgram.createSocket('udp4'); const errorMessageOffset = - /^The "offset" argument must be of type number$/; + /^The "offset" argument must be of type number\. Received /; assert.throws(() => { socket.sendto(); @@ -20,7 +20,7 @@ assert.throws(() => { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /^The "length" argument must be of type number$/ + message: /^The "length" argument must be of type number\. Received / })); assert.throws(() => { @@ -36,7 +36,7 @@ assert.throws(() => { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /^The "address" argument must be of type string$/ + message: /^The "address" argument must be of type string\. Received / })); assert.throws(() => { @@ -44,5 +44,5 @@ assert.throws(() => { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /^The "port" argument must be of type number$/ + message: /^The "port" argument must be of type number\. Received / })); diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js index 8e06bab34944a1..d01617736d89ff 100644 --- a/test/parallel/test-internal-errors.js +++ b/test/parallel/test-internal-errors.js @@ -181,24 +181,42 @@ assert.throws(() => { })); // // Test ERR_INVALID_ARG_TYPE -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b']), - 'The "a" argument must be of type b'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', ['b']]), - 'The "a" argument must be of type b'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', ['b', 'c']]), - 'The "a" argument must be one of type b or c'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', - ['a', ['b', 'c', 'd']]), - 'The "a" argument must be one of type b, c, or d'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b', 'c']), - 'The "a" argument must be of type b. Received type string'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', - ['a', 'b', undefined]), - 'The "a" argument must be of type b. Received type ' + - 'undefined'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', - ['a', 'b', null]), - 'The "a" argument must be of type b. Received type null'); +const specialArray = []; +Object.defineProperty(specialArray, 'constructor', { + enumerable: false, + configurable: false, + writable: false, + value: null +}); +assert.strictEqual( + errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b', specialArray]), + 'The "a" argument must be of type b. Received a plain object' +); +assert.strictEqual( + errors.message('ERR_INVALID_ARG_TYPE', ['a', ['b'], new Error()]), + 'The "a" argument must be of type b. Received instance of Error' +); +assert.strictEqual( + errors.message('ERR_INVALID_ARG_TYPE', + ['a', ['b', 'Array'], Object.create(null)]), + 'The "a" argument must be of type b or Array. Received a plain object' +); +assert.strictEqual( + errors.message('ERR_INVALID_ARG_TYPE', ['a', ['Array', 'c', 'd'], null]), + 'The "a" argument must be instance of Array, c, or d. Received null' +); +assert.strictEqual( + errors.message('ERR_INVALID_ARG_TYPE', ['a', 'B', 'c']), + 'The "a" argument must be instance of B. Received type string' +); +assert.strictEqual( + errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b', undefined]), + 'The "a" argument must be of type b. Received undefined' +); +assert.strictEqual( + errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b', /a/]), + 'The "a" argument must be of type b. Received instance of RegExp' +); // Test ERR_INVALID_URL_SCHEME assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', ['file']), @@ -206,9 +224,9 @@ assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', ['file']), assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['file']]), 'The URL must be of scheme file'); assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['http', 'ftp']]), - 'The URL must be one of scheme http or ftp'); + 'The URL must be of scheme http or ftp'); assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['a', 'b', 'c']]), - 'The URL must be one of scheme a, b, or c'); + 'The URL must be of scheme a, b, or c'); assert.throws( () => errors.message('ERR_INVALID_URL_SCHEME', [[]]), common.expectsError({ diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index b253249472cb08..5e44e35f6616ab 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -209,7 +209,14 @@ function checkFormat(path, testCases) { }); function typeName(value) { - return value === null ? 'null' : typeof value; + if (value == null) { + return value; + } + const type = typeof value; + if (type !== 'object') { + return `type ${type}`; + } + return `instance of ${value.constructor.name}`; } [null, undefined, 1, true, false, 'string'].forEach((pathObject) => { @@ -218,8 +225,8 @@ function checkFormat(path, testCases) { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "pathObject" argument must be of type Object. Received ' + - 'type ' + typeName(pathObject) + message: 'The "pathObject" argument must be of type object. Received ' + + typeName(pathObject) })); }); } diff --git a/test/parallel/test-process-cpuUsage.js b/test/parallel/test-process-cpuUsage.js index a6e799ca1b3213..f2b64ed8af09d9 100644 --- a/test/parallel/test-process-cpuUsage.js +++ b/test/parallel/test-process-cpuUsage.js @@ -34,13 +34,13 @@ for (let i = 0; i < 10; i++) { const invalidUserArgument = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "preValue.user" property must be of type Number' + message: /^The "prevValue\.user" property must be of type number\. Received / }, 8); const invalidSystemArgument = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "preValue.system" property must be of type Number' + message: /^The "prevValue\.system" property must be of type number\./ }, 2); diff --git a/test/parallel/test-process-hrtime.js b/test/parallel/test-process-hrtime.js index faf05fef112cb7..5ce5da6bba665e 100644 --- a/test/parallel/test-process-hrtime.js +++ b/test/parallel/test-process-hrtime.js @@ -38,7 +38,8 @@ assert.throws(() => { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "time" argument must be of type Array. Received type number' + message: 'The "time" argument must be instance of Array. ' + + 'Received type number' })); assert.throws(() => { process.hrtime([]); diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index 994a19f5ccea8b..6842f02046dfab 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -41,7 +41,7 @@ const assert = require('assert'); const invalidPidArgument = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "pid" argument must be of type Number' + message: /^The "pid" argument must be of type number\. Received / }, 6); assert.throws(function() { process.kill('SIGTERM'); }, diff --git a/test/parallel/test-url-format-invalid-input.js b/test/parallel/test-url-format-invalid-input.js index cc4f6bdc0f178c..b641762b6a52b8 100644 --- a/test/parallel/test-url-format-invalid-input.js +++ b/test/parallel/test-url-format-invalid-input.js @@ -6,19 +6,19 @@ const url = require('url'); const throwsObjsAndReportTypes = new Map([ [undefined, 'undefined'], [null, 'null'], - [true, 'boolean'], - [false, 'boolean'], - [0, 'number'], - [function() {}, 'function'], - [Symbol('foo'), 'symbol'] + [true, 'type boolean'], + [false, 'type boolean'], + [0, 'type number'], + [function() {}, 'type function'], + [Symbol('foo'), 'type symbol'] ]); for (const [urlObject, type] of throwsObjsAndReportTypes) { const error = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "urlObject" argument must be one of type object or string. ' + - `Received type ${type}` + message: 'The "urlObject" argument must be of type object or string. ' + + `Received ${type}` }); assert.throws(function() { url.format(urlObject); }, error); } diff --git a/test/parallel/test-url-format-whatwg.js b/test/parallel/test-url-format-whatwg.js index d6afe46426b2ac..8c30258c2153a6 100644 --- a/test/parallel/test-url-format-whatwg.js +++ b/test/parallel/test-url-format-whatwg.js @@ -24,7 +24,7 @@ assert.strictEqual( const expectedErr = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type object' + message: /^The "options" argument must be of type object\. Received / }, 4); assert.throws(() => url.format(myURL, true), expectedErr); assert.throws(() => url.format(myURL, 1), expectedErr); diff --git a/test/parallel/test-url-parse-invalid-input.js b/test/parallel/test-url-parse-invalid-input.js index 86751a2935a7bf..1e44ef0e5b2731 100644 --- a/test/parallel/test-url-parse-invalid-input.js +++ b/test/parallel/test-url-parse-invalid-input.js @@ -7,19 +7,19 @@ const url = require('url'); [ [undefined, 'undefined'], [null, 'null'], - [true, 'boolean'], - [false, 'boolean'], - [0.0, 'number'], - [0, 'number'], - [[], 'object'], - [{}, 'object'], - [() => {}, 'function'], - [Symbol('foo'), 'symbol'] + [true, 'type boolean'], + [false, 'type boolean'], + [0.0, 'type number'], + [0, 'type number'], + [[], 'instance of Array'], + [{}, 'instance of Object'], + [() => {}, 'type function'], + [Symbol('foo'), 'type symbol'] ].forEach(([val, type]) => { const error = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: `The "url" argument must be of type string. Received type ${type}` + message: `The "url" argument must be of type string. Received ${type}` }); assert.throws(() => { url.parse(val); }, error); }); diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js index 68ffc6e9207e23..18872d20bc2842 100644 --- a/test/parallel/test-util-callbackify.js +++ b/test/parallel/test-util-callbackify.js @@ -234,7 +234,7 @@ const values = [ }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "original" argument must be of type function' + message: /^The "original" argument must be of type function\. Received / })); }); } @@ -255,7 +255,7 @@ const values = [ }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "last argument" argument must be of type function' + message: /^The "last argument" argument must be of type function\./ })); }); } diff --git a/test/parallel/test-util-inherits.js b/test/parallel/test-util-inherits.js index 31b7e6ad3d6b15..380d607e343993 100644 --- a/test/parallel/test-util-inherits.js +++ b/test/parallel/test-util-inherits.js @@ -6,7 +6,7 @@ const inherits = require('util').inherits; const errCheck = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "superCtor" argument must be of type function' + message: /The "superCtor" argument must be of type function/ }); // super constructor @@ -85,7 +85,7 @@ assert.throws(function() { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', 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() { @@ -96,6 +96,6 @@ assert.throws(function() { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "ctor" argument must be of type function' + message: 'The "ctor" argument must be of type function. Received null' }) ); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 3b3b93dc00353b..4dd74f19f045ef 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1032,7 +1032,7 @@ if (typeof Symbol !== 'undefined') { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type object' + message: 'The "options" argument must be of type object. Received null' }) ); @@ -1041,7 +1041,7 @@ if (typeof Symbol !== 'undefined') { }, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type object' + message: /^The "options" argument must be of type object\. Received / }) ); }