From ac2fc0dd5f5830d32dd89fe1c9c55d672cf59c0a Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 23 Sep 2019 08:17:25 +0200 Subject: [PATCH] errors: improve ERR_INVALID_ARG_TYPE ERR_INVALID_ARG_TYPE is the most common error used throughout the code base. This improves the error message by providing more details to the user and by indicating more precisely which values are allowed ones and which ones are not. It adds the actual input to the error message in case it's a primitive. If it's a class instance, it'll print the class name instead of "object" and "falsy" or similar entries are not named "type" anymore. PR-URL: https://github.com/nodejs/node/pull/29675 Reviewed-By: Rich Trott --- lib/internal/errors.js | 156 ++++++++++++++---- test/common/index.js | 21 +++ test/es-module/test-esm-loader-modulemap.js | 13 +- test/internet/test-dns-promises-resolve.js | 2 +- test/parallel/test-assert-async.js | 8 +- test/parallel/test-assert.js | 22 +-- test/parallel/test-buffer-alloc.js | 12 +- test/parallel/test-buffer-arraybuffer.js | 5 +- test/parallel/test-buffer-bytelength.js | 5 +- test/parallel/test-buffer-compare-offset.js | 4 +- test/parallel/test-buffer-compare.js | 12 +- test/parallel/test-buffer-concat.js | 12 +- test/parallel/test-buffer-equals.js | 4 +- test/parallel/test-buffer-fill.js | 5 +- test/parallel/test-buffer-from.js | 36 ++-- test/parallel/test-buffer-includes.js | 5 +- test/parallel/test-buffer-indexof.js | 5 +- test/parallel/test-buffer-new.js | 3 +- .../test-child-process-constructor.js | 20 +-- test/parallel/test-child-process-fork.js | 2 +- test/parallel/test-console-instance.js | 2 +- test/parallel/test-crypto-certificate.js | 9 +- test/parallel/test-crypto-cipher-decipher.js | 24 +-- .../test-crypto-cipheriv-decipheriv.js | 20 +-- test/parallel/test-crypto-dh.js | 7 +- test/parallel/test-crypto-engine.js | 6 +- test/parallel/test-crypto-hash.js | 6 +- test/parallel/test-crypto-hmac.js | 6 +- test/parallel/test-crypto-key-objects.js | 16 +- test/parallel/test-crypto-keygen.js | 12 +- test/parallel/test-crypto-pbkdf2.js | 30 ++-- test/parallel/test-crypto-random.js | 9 +- test/parallel/test-crypto-sign-verify.js | 35 ++-- test/parallel/test-dgram-custom-lookup.js | 4 +- test/parallel/test-dgram-multicast-setTTL.js | 3 +- .../parallel/test-dgram-send-address-types.js | 4 +- .../parallel/test-dgram-send-bad-arguments.js | 12 +- test/parallel/test-dgram-sendto.js | 10 +- test/parallel/test-dgram-setTTL.js | 3 +- .../test-dns-setservers-type-check.js | 10 +- test/parallel/test-dns.js | 6 +- .../test-event-emitter-add-listeners.js | 4 +- test/parallel/test-event-emitter-once.js | 4 +- test/parallel/test-event-emitter-prepend.js | 4 +- .../test-event-emitter-remove-listeners.js | 4 +- test/parallel/test-fs-buffer.js | 4 +- test/parallel/test-fs-chmod.js | 5 +- test/parallel/test-fs-close-errors.js | 6 +- test/parallel/test-fs-fchmod.js | 6 +- test/parallel/test-fs-fchown.js | 5 +- test/parallel/test-fs-fsync.js | 4 +- test/parallel/test-fs-mkdir.js | 9 +- test/parallel/test-fs-promises.js | 4 +- test/parallel/test-fs-read-type.js | 16 +- test/parallel/test-fs-read.js | 2 +- test/parallel/test-fs-readfile-error.js | 4 +- test/parallel/test-fs-rename-type-check.js | 11 +- test/parallel/test-fs-stat.js | 4 +- test/parallel/test-fs-symlink.js | 4 +- test/parallel/test-fs-truncate.js | 15 +- test/parallel/test-fs-watch.js | 4 +- .../test-http-client-check-http-token.js | 4 +- ...est-http-client-reject-unexpected-agent.js | 5 +- .../test-http-hostname-typechecking.js | 13 +- test/parallel/test-http-mutable-headers.js | 8 +- test/parallel/test-http-outgoing-proto.js | 8 +- ...est-http2-client-setNextStreamID-errors.js | 4 +- ...test-http2-compat-serverrequest-headers.js | 2 +- ...est-http2-compat-serverresponse-headers.js | 4 +- ...st-http2-compat-serverresponse-trailers.js | 2 +- .../test-http2-createsecureserver-options.js | 8 +- .../test-http2-createserver-options.js | 8 +- test/parallel/test-http2-getpackedsettings.js | 4 +- .../test-http2-invalidargtypes-errors.js | 2 +- test/parallel/test-http2-misc-util.js | 6 +- test/parallel/test-http2-ping.js | 5 +- .../test-http2-respond-file-fd-errors.js | 5 +- ...st-http2-server-shutdown-options-errors.js | 13 +- test/parallel/test-http2-timeouts.js | 3 +- test/parallel/test-http2-util-asserts.js | 13 +- .../test-https-options-boolean-check.js | 25 +-- test/parallel/test-icu-transcode.js | 4 +- .../test-internal-module-map-asserts.js | 26 ++- test/parallel/test-module-loading-error.js | 2 +- test/parallel/test-net-write-arguments.js | 4 +- test/parallel/test-path-parse-format.js | 4 +- test/parallel/test-performance-function.js | 3 +- test/parallel/test-performanceobserver.js | 4 +- test/parallel/test-process-cpuUsage.js | 12 +- test/parallel/test-process-euid-egid.js | 2 +- .../test-process-exception-capture-errors.js | 4 +- test/parallel/test-process-hrtime.js | 3 +- test/parallel/test-process-initgroups.js | 8 +- test/parallel/test-process-kill-pid.js | 4 +- test/parallel/test-process-setgroups.js | 8 +- test/parallel/test-process-uid-gid.js | 2 +- test/parallel/test-require-resolve.js | 7 +- test/parallel/test-string-decoder.js | 4 +- test/parallel/test-tls-basic-validations.js | 8 +- ...t-tls-clientcertengine-invalid-arg-type.js | 2 +- test/parallel/test-tls-error-servername.js | 4 +- .../test-tls-keyengine-invalid-arg-type.js | 4 +- test/parallel/test-tls-no-cert-required.js | 15 +- .../test-tls-options-boolean-check.js | 25 +-- .../parallel/test-url-format-invalid-input.js | 24 +-- test/parallel/test-url-format-whatwg.js | 4 +- test/parallel/test-url-parse-invalid-input.js | 3 +- test/parallel/test-util-callbackify.js | 8 +- .../test-util-deprecate-invalid-code.js | 4 +- test/parallel/test-util-inherits.js | 10 +- test/parallel/test-util-inspect.js | 8 +- test/parallel/test-util-promisify.js | 4 +- test/parallel/test-uv-errno.js | 4 +- test/parallel/test-v8-flag-type-check.js | 4 +- test/parallel/test-vm-basic.js | 32 ++-- test/parallel/test-vm-cached-data.js | 2 +- test/parallel/test-vm-context.js | 13 +- test/parallel/test-vm-module-errors.js | 10 +- test/parallel/test-worker-process-env.js | 5 +- test/parallel/test-worker-type-check.js | 4 +- .../parallel/test-zlib-convenience-methods.js | 2 +- .../test-zlib-deflate-constructors.js | 19 ++- test/parallel/test-zlib-flush-flags.js | 4 +- .../test-zlib-not-string-or-buffer.js | 6 +- .../test-crypto-timing-safe-equal.js | 8 +- test/sequential/test-heapdump.js | 5 +- test/sequential/test-inspector-module.js | 8 +- 127 files changed, 664 insertions(+), 533 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index ad12d99c7cc49c..8b0a7a0d7aab66 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -23,6 +23,21 @@ const { const messages = new Map(); const codes = {}; +const classRegExp = /^([A-Z][a-z0-9]*)+$/; +// Sorted by a rough estimate on most frequently used entries. +const kTypes = [ + 'string', + 'function', + 'number', + 'object', + // Accept 'Function' and 'Object' as alternative to the lower cased version. + 'Function', + 'Object', + 'boolean', + 'bigint', + 'symbol' +]; + const { kMaxLength } = internalBinding('buffer'); const MainContextError = Error; @@ -610,26 +625,6 @@ function isStackOverflowError(err) { err.message === maxStack_ErrorMessage; } -function oneOf(expected, thing) { - assert(typeof thing === 'string', '`thing` has to be of type string'); - if (ArrayIsArray(expected)) { - const len = expected.length; - 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 ` + - expected[len - 1]; - } else if (len === 2) { - return `one of ${thing} ${expected[0]} or ${expected[1]}`; - } else { - return `of ${thing} ${expected[0]}`; - } - } else { - return `of ${thing} ${String(expected)}`; - } -} - // Only use this for integers! Decimal numbers do not work with this function. function addNumericalSeparator(val) { let res = ''; @@ -926,27 +921,114 @@ E('ERR_INVALID_ADDRESS_FAMILY', function(addressType, host, port) { E('ERR_INVALID_ARG_TYPE', (name, expected, actual) => { assert(typeof name === 'string', "'name' must be a string"); + if (!ArrayIsArray(expected)) { + expected = [expected]; + } + + let msg = 'The '; + if (name.endsWith(' argument')) { + // For cases like 'first argument' + msg += `${name} `; + } else { + const type = name.includes('.') ? 'property' : 'argument'; + msg += `"${name}" ${type} `; + } // determiner: 'must be' or 'must not be' - let determiner; if (typeof expected === 'string' && expected.startsWith('not ')) { - determiner = 'must not be'; + msg += 'must not be '; expected = expected.replace(/^not /, ''); } else { - determiner = 'must be'; + msg += 'must be '; } - let msg; - if (name.endsWith(' argument')) { - // For cases like 'first argument' - msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`; - } else { - const type = name.includes('.') ? 'property' : 'argument'; - msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, 'type')}`; + const types = []; + const instances = []; + const other = []; + + for (const value of expected) { + assert(typeof value === 'string', + 'All expected entries have to be of type string'); + if (kTypes.includes(value)) { + types.push(value.toLowerCase()); + } else if (classRegExp.test(value)) { + instances.push(value); + } else { + assert(value !== 'object', + 'The value "object" should be written as "Object"'); + other.push(value); + } } - // TODO(BridgeAR): Improve the output by showing `null` and similar. - msg += `. Received type ${typeof actual}`; + // Special handle `object` in case other instances are allowed to outline + // the differences between each other. + if (instances.length > 0) { + const pos = types.indexOf('object'); + if (pos !== -1) { + types.splice(pos, 1); + instances.push('Object'); + } + } + + if (types.length > 0) { + if (types.length > 2) { + const last = types.pop(); + msg += `one of type ${types.join(', ')}, or ${last}`; + } else if (types.length === 2) { + msg += `one of type ${types[0]} or ${types[1]}`; + } else { + msg += `of type ${types[0]}`; + } + if (instances.length > 0 || other.length > 0) + msg += ' or '; + } + + if (instances.length > 0) { + if (instances.length > 2) { + const last = instances.pop(); + msg += `an instance of ${instances.join(', ')}, or ${last}`; + } else { + msg += `an instance of ${instances[0]}`; + if (instances.length === 2) { + msg += ` or ${instances[1]}`; + } + } + if (other.length > 0) + msg += ' or '; + } + + if (other.length > 0) { + if (other.length > 2) { + const last = other.pop(); + msg += `one of ${other.join(', ')}, or ${last}`; + } else if (other.length === 2) { + msg += `one of ${other[0]} or ${other[1]}`; + } else { + if (other[0].toLowerCase() !== other[0]) + msg += 'an '; + msg += `${other[0]}`; + } + } + + if (actual == null) { + msg += `. Received ${actual}`; + } else if (typeof actual === 'function' && actual.name) { + msg += `. Received function ${actual.name}`; + } else if (typeof actual === 'object') { + if (actual.constructor && actual.constructor.name) { + msg += `. Received an instance of ${actual.constructor.name}`; + } else { + const inspected = lazyInternalUtilInspect() + .inspect(actual, { depth: -1 }); + msg += `. Received ${inspected}`; + } + } else { + let inspected = lazyInternalUtilInspect() + .inspect(actual, { colors: false }); + if (inspected.length > 25) + inspected = `${inspected.slice(0, 25)}...`; + msg += `. Received type ${typeof actual} (${inspected})`; + } return msg; }, TypeError); E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => { @@ -1034,7 +1116,15 @@ E('ERR_INVALID_URL', function(input) { return `Invalid URL: ${input}`; }, TypeError); E('ERR_INVALID_URL_SCHEME', - (expected) => `The URL must be ${oneOf(expected, 'scheme')}`, TypeError); + (expected) => { + if (typeof expected === 'string') + expected = [expected]; + assert(expected.length <= 2); + const res = expected.length === 2 ? + `one of scheme ${expected[0]} or ${expected[1]}` : + `of scheme ${expected[0]}`; + return `The URL must be ${res}`; + }, TypeError); E('ERR_IPC_CHANNEL_CLOSED', 'Channel closed', Error); E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected', Error); E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe', Error); diff --git a/test/common/index.js b/test/common/index.js index d774bffe0fadb5..a320a1bebfefd3 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -718,6 +718,26 @@ function runWithInvalidFD(func) { printSkipMessage('Could not generate an invalid fd'); } +// A helper function to simplify checking for ERR_INVALID_ARG_TYPE output. +function invalidArgTypeHelper(input) { + if (input == null) { + return ` Received ${input}`; + } + if (typeof input === 'function' && input.name) { + return ` Received function ${input.name}`; + } + if (typeof input === 'object') { + if (input.constructor && input.constructor.name) { + return ` Received an instance of ${input.constructor.name}`; + } + return ` Received ${util.inspect(input, { depth: -1 })}`; + } + let inspected = util.inspect(input, { colors: false }); + if (inspected.length > 25) + inspected = `${inspected.slice(0, 25)}...`; + return ` Received type ${typeof input} (${inspected})`; +} + module.exports = { allowGlobals, buildType, @@ -735,6 +755,7 @@ module.exports = { hasIntl, hasCrypto, hasMultiLocalhost, + invalidArgTypeHelper, isAIX, isAlive, isFreeBSD, diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index 5493c6c47c9643..1a9e6dea826c21 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -25,7 +25,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "url" argument must be of type string. Received type number' + message: 'The "url" argument must be of type string. Received type number' + + ' (1)' } ); @@ -34,7 +35,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "url" argument must be of type string. Received type number' + message: 'The "url" argument must be of type string. Received type number' + + ' (1)' } ); @@ -43,8 +45,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "job" argument must be of type ModuleJob. ' + - 'Received type string' + message: 'The "job" argument must be an instance of ModuleJob. ' + + "Received type string ('notamodulejob')" } ); @@ -53,6 +55,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "url" argument must be of type string. Received type number' + message: 'The "url" argument must be of type string. Received type number' + + ' (1)' } ); diff --git a/test/internet/test-dns-promises-resolve.js b/test/internet/test-dns-promises-resolve.js index 6291e0365c2fa4..b9e7fa42302c0d 100644 --- a/test/internet/test-dns-promises-resolve.js +++ b/test/internet/test-dns-promises-resolve.js @@ -26,7 +26,7 @@ const dnsPromises = require('dns').promises; code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "rrtype" argument must be of type string. ' + - `Received type ${typeof rrtype}` + `Received type ${typeof rrtype} (${rrtype})` } ); } diff --git a/test/parallel/test-assert-async.js b/test/parallel/test-assert-async.js index cbb4431f1952df..dd98c0a23339ec 100644 --- a/test/parallel/test-assert-async.js +++ b/test/parallel/test-assert-async.js @@ -125,8 +125,8 @@ promises.push(assert.rejects( assert.rejects('fail', {}), { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "promiseFn" argument must be one of type ' + - 'Function or Promise. Received type string' + message: 'The "promiseFn" argument must be of type function or an ' + + "instance of Promise. Received type string ('fail')" } )); @@ -225,8 +225,8 @@ promises.push(assert.rejects( assert.doesNotReject(123), { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "promiseFn" argument must be one of type ' + - 'Function or Promise. Received type number' + message: 'The "promiseFn" argument must be of type ' + + 'function or an instance of Promise. Received type number (123)' } )); /* eslint-enable no-restricted-syntax */ diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 3db63a816a5294..85eb1de5bf471d 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -414,8 +414,8 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "fn" argument must be of type Function. Received ' + - `type ${typeof fn}` + message: 'The "fn" argument must be of type function.' + + common.invalidArgTypeHelper(fn) } ); }; @@ -484,8 +484,8 @@ assert.throws(() => { { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "options" argument must be of type Object. ' + - `Received type ${typeof input}` + message: 'The "options" argument must be of type object.' + + common.invalidArgTypeHelper(input) }); }); } @@ -937,8 +937,9 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "error" argument must be one of type Object, Error, ' + - 'Function, or RegExp. Received type string' + message: 'The "error" argument must be of type function or ' + + 'an instance of Error, RegExp, or Object. Received type string ' + + "('Error message')" } ); @@ -951,8 +952,9 @@ common.expectsError( () => assert.throws(() => {}, input), { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "error" argument must be one of type Object, Error, ' + - `Function, or RegExp. Received type ${typeof input}` + message: 'The "error" argument must be of type function or ' + + 'an instance of Error, RegExp, or Object.' + + common.invalidArgTypeHelper(input) } ); }); @@ -1030,8 +1032,8 @@ common.expectsError( { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "expected" argument must be one of type Function or ' + - 'RegExp. Received type object' + message: 'The "expected" argument must be of type function or an ' + + 'instance of RegExp. Received an instance of Object' } ); diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index de3e7fa52390f0..75bcb03d1913c4 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -967,19 +967,19 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "target" argument must be one of type Buffer or Uint8Array.' + - ' Received type undefined' + message: 'The "target" argument must be an instance of Buffer or ' + + 'Uint8Array. Received undefined' }); assert.throws(() => Buffer.from(), { name: 'TypeError', - message: 'The first argument must be one of type string, Buffer, ' + - 'ArrayBuffer, Array, or Array-like Object. Received type undefined' + message: 'The first argument must be of type string or an instance of ' + + 'Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined' }); assert.throws(() => Buffer.from(null), { name: 'TypeError', - message: 'The first argument must be one of type string, Buffer, ' + - 'ArrayBuffer, Array, or Array-like Object. Received type object' + message: 'The first argument must be of type string or an instance of ' + + 'Buffer, ArrayBuffer, or Array or an Array-like Object. Received null' }); // Test prototype getters don't throw diff --git a/test/parallel/test-buffer-arraybuffer.js b/test/parallel/test-buffer-arraybuffer.js index 699d13e9552a91..bb22b879932571 100644 --- a/test/parallel/test-buffer-arraybuffer.js +++ b/test/parallel/test-buffer-arraybuffer.js @@ -43,8 +43,9 @@ assert.throws(function() { }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The first argument must be one of type string, Buffer,' + - ' ArrayBuffer, Array, or Array-like Object. Received type object' + message: 'The first argument must be of type string or an instance of ' + + 'Buffer, ArrayBuffer, or Array or an Array-like Object. Received ' + + 'an instance of AB' }); // Test the byteOffset and length arguments diff --git a/test/parallel/test-buffer-bytelength.js b/test/parallel/test-buffer-bytelength.js index c0c7228d0d0b45..369e8cb191616e 100644 --- a/test/parallel/test-buffer-bytelength.js +++ b/test/parallel/test-buffer-bytelength.js @@ -16,8 +16,9 @@ const vm = require('vm'); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "string" argument must be one of type string, ' + - `Buffer, or ArrayBuffer. Received type ${typeof args[0]}` + message: 'The "string" argument must be of type string or an instance ' + + 'of Buffer or ArrayBuffer.' + + common.invalidArgTypeHelper(args[0]) } ); }); diff --git a/test/parallel/test-buffer-compare-offset.js b/test/parallel/test-buffer-compare-offset.js index 3769e4d41ac27e..df3b429a03c4df 100644 --- a/test/parallel/test-buffer-compare-offset.js +++ b/test/parallel/test-buffer-compare-offset.js @@ -89,6 +89,6 @@ assert.throws(() => a.compare(b, -Infinity, Infinity), oor); common.expectsError(() => a.compare(), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "target" argument must be one of ' + - 'type Buffer or Uint8Array. Received type undefined' + message: 'The "target" argument must be an instance of ' + + 'Buffer or Uint8Array. Received undefined' }); diff --git a/test/parallel/test-buffer-compare.js b/test/parallel/test-buffer-compare.js index e2bd1380d2ce15..b790e461bcfa63 100644 --- a/test/parallel/test-buffer-compare.js +++ b/test/parallel/test-buffer-compare.js @@ -30,18 +30,18 @@ assert.strictEqual(Buffer.compare(Buffer.alloc(1), Buffer.alloc(0)), 1); assert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'), { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "buf2" argument must be one of type Buffer or Uint8Array. ' + - 'Received type string' + message: 'The "buf2" argument must be an instance of Buffer or Uint8Array. ' + + "Received type string ('abc')" }); assert.throws(() => Buffer.compare('abc', Buffer.alloc(1)), { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "buf1" argument must be one of type Buffer or Uint8Array. ' + - 'Received type string' + message: 'The "buf1" argument must be an instance of Buffer or Uint8Array. ' + + "Received type string ('abc')" }); common.expectsError(() => Buffer.alloc(1).compare('abc'), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "target" argument must be one of ' + - 'type Buffer or Uint8Array. Received type string' + message: 'The "target" argument must be an instance of ' + + "Buffer or Uint8Array. Received type string ('abc')" }); diff --git a/test/parallel/test-buffer-concat.js b/test/parallel/test-buffer-concat.js index 6be3a39fa00a26..2e7541fb58b063 100644 --- a/test/parallel/test-buffer-concat.js +++ b/test/parallel/test-buffer-concat.js @@ -49,8 +49,8 @@ assert.strictEqual(flatLongLen.toString(), check); Buffer.concat(value); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "list" argument must be of type Array. ' + - `Received type ${typeof value}` + message: 'The "list" argument must be an instance of Array.' + + `${common.invalidArgTypeHelper(value)}` }); }); @@ -59,8 +59,8 @@ assert.strictEqual(flatLongLen.toString(), check); Buffer.concat(value); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "list[0]" argument must be one of type Buffer ' + - `or Uint8Array. Received type ${typeof value[0]}` + message: 'The "list[0]" argument must be an instance of Buffer ' + + `or Uint8Array.${common.invalidArgTypeHelper(value[0])}` }); }); @@ -68,8 +68,8 @@ assert.throws(() => { Buffer.concat([Buffer.from('hello'), 3]); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "list[1]" argument must be one of type Buffer ' + - 'or Uint8Array. Received type number' + message: 'The "list[1]" argument must be an instance of Buffer ' + + 'or Uint8Array. Received type number (3)' }); // eslint-disable-next-line node-core/crypto-check diff --git a/test/parallel/test-buffer-equals.js b/test/parallel/test-buffer-equals.js index 91c79a5be8b169..055fe56de26f08 100644 --- a/test/parallel/test-buffer-equals.js +++ b/test/parallel/test-buffer-equals.js @@ -19,7 +19,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "otherBuffer" argument must be one of type ' + - 'Buffer or Uint8Array. Received type string' + message: 'The "otherBuffer" argument must be an instance of ' + + "Buffer or Uint8Array. Received type string ('abc')" } ); diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js index 26243d7f199f12..aa5c701b543c98 100644 --- a/test/parallel/test-buffer-fill.js +++ b/test/parallel/test-buffer-fill.js @@ -196,7 +196,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', message: 'The "encoding" argument must be of type ' + - `string. Received type ${args[3] === null ? 'null' : typeof args[3]}` + `string.${common.invalidArgTypeHelper(args[3])}` } ); }); @@ -342,7 +342,8 @@ assert.strictEqual( Buffer.alloc(1).fill(Buffer.alloc(1), 0, end); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "end" argument must be of type number. Received type object' + message: 'The "end" argument must be of type number. Received an ' + + 'instance of Object' }); } diff --git a/test/parallel/test-buffer-from.js b/test/parallel/test-buffer-from.js index ec798381696e71..165b38893f9e99 100644 --- a/test/parallel/test-buffer-from.js +++ b/test/parallel/test-buffer-from.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +const common = require('../common'); const { deepStrictEqual, throws } = require('assert'); const { runInNewContext } = require('vm'); @@ -35,26 +35,26 @@ deepStrictEqual( ); [ - [{}, 'object'], - [new Boolean(true), 'boolean'], - [{ valueOf() { return null; } }, 'object'], - [{ valueOf() { return undefined; } }, 'object'], - [{ valueOf: null }, 'object'], - [Object.create(null), 'object'], - [new Number(true), 'number'], - [new MyBadPrimitive(), 'number'], - [Symbol(), 'symbol'], - [5n, 'bigint'], - [(one, two, three) => {}, 'function'], - [undefined, 'undefined'], - [null, 'object'] -].forEach(([input, actualType]) => { + {}, + new Boolean(true), + { valueOf() { return null; } }, + { valueOf() { return undefined; } }, + { valueOf: null }, + Object.create(null), + new Number(true), + new MyBadPrimitive(), + Symbol(), + 5n, + (one, two, three) => {}, + undefined, + null +].forEach((input) => { const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The first argument must be one of type string, Buffer, ' + - 'ArrayBuffer, Array, or Array-like Object. Received ' + - `type ${actualType}` + message: 'The first argument must be of type string or an instance of ' + + 'Buffer, ArrayBuffer, or Array or an Array-like Object.' + + common.invalidArgTypeHelper(input) }; throws(() => Buffer.from(input), errObj); throws(() => Buffer.from(input, 'hex'), errObj); diff --git a/test/parallel/test-buffer-includes.js b/test/parallel/test-buffer-includes.js index 794822f13ac873..8e5ec8e926cbb9 100644 --- a/test/parallel/test-buffer-includes.js +++ b/test/parallel/test-buffer-includes.js @@ -282,8 +282,9 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "value" argument must be one of type number, string, ' + - `Buffer, or Uint8Array. Received type ${typeof val}` + message: 'The "value" argument must be one of type number or string ' + + 'or an instance of Buffer or Uint8Array.' + + common.invalidArgTypeHelper(val) } ); }); diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js index 3059e13780e5bd..4eb42ca5bff8fa 100644 --- a/test/parallel/test-buffer-indexof.js +++ b/test/parallel/test-buffer-indexof.js @@ -357,8 +357,9 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "value" argument must be one of type number, string, ' + - `Buffer, or Uint8Array. Received type ${typeof val}` + message: 'The "value" argument must be one of type number or string ' + + 'or an instance of Buffer or Uint8Array.' + + common.invalidArgTypeHelper(val) } ); }); diff --git a/test/parallel/test-buffer-new.js b/test/parallel/test-buffer-new.js index 31b29dee5b0815..45806359ad6cb4 100644 --- a/test/parallel/test-buffer-new.js +++ b/test/parallel/test-buffer-new.js @@ -5,5 +5,6 @@ const common = require('../common'); common.expectsError(() => new Buffer(42, 'utf8'), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "string" argument must be of type string. Received type number' + message: 'The "string" argument must be of type string. Received type ' + + 'number (42)' }); diff --git a/test/parallel/test-child-process-constructor.js b/test/parallel/test-child-process-constructor.js index 9c9ed2d0e84900..9c5b09171c66dd 100644 --- a/test/parallel/test-child-process-constructor.js +++ b/test/parallel/test-child-process-constructor.js @@ -5,10 +5,6 @@ const assert = require('assert'); const { ChildProcess } = require('child_process'); assert.strictEqual(typeof ChildProcess, 'function'); -function typeName(value) { - return typeof value; -} - { // Verify that invalid options to spawn() throw. const child = new ChildProcess(); @@ -19,8 +15,8 @@ function typeName(value) { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type Object. ' + - `Received type ${typeName(options)}` + message: 'The "options" argument must be of type object.' + + `${common.invalidArgTypeHelper(options)}` }); }); } @@ -35,8 +31,8 @@ function typeName(value) { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.file" property must be of type string. ' + - `Received type ${typeName(file)}` + message: 'The "options.file" property must be of type string.' + + `${common.invalidArgTypeHelper(file)}` }); }); } @@ -51,8 +47,8 @@ function typeName(value) { }, { 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 an instance of Array.' + + common.invalidArgTypeHelper(envPairs) }); }); } @@ -67,8 +63,8 @@ function typeName(value) { }, { 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 an instance of Array.' + + common.invalidArgTypeHelper(args) }); }); } diff --git a/test/parallel/test-child-process-fork.js b/test/parallel/test-child-process-fork.js index 44d22ab2115e91..a771f84e681fd9 100644 --- a/test/parallel/test-child-process-fork.js +++ b/test/parallel/test-child-process-fork.js @@ -52,7 +52,7 @@ assert.throws(() => n.send(), { assert.throws(() => n.send(Symbol()), { name: 'TypeError', message: 'The "message" argument must be one of type string,' + - ' object, number, or boolean. Received type symbol', + ' object, number, or boolean. Received type symbol (Symbol())', code: 'ERR_INVALID_ARG_TYPE' }); n.send({ hello: 'world' }); diff --git a/test/parallel/test-console-instance.js b/test/parallel/test-console-instance.js index 1c8b54ef4ca725..0356690a4d348f 100644 --- a/test/parallel/test-console-instance.js +++ b/test/parallel/test-console-instance.js @@ -141,7 +141,7 @@ out.write = err.write = (d) => {}; }, { message: 'The "inspectOptions" argument must be of type object.' + - ` Received type ${typeof inspectOptions}`, + common.invalidArgTypeHelper(inspectOptions), code: 'ERR_INVALID_ARG_TYPE' } ); diff --git a/test/parallel/test-crypto-certificate.js b/test/parallel/test-crypto-certificate.js index e987be212958a7..8d3219059d039e 100644 --- a/test/parallel/test-crypto-certificate.js +++ b/test/parallel/test-crypto-certificate.js @@ -75,8 +75,8 @@ assert(Certificate() instanceof Certificate); () => Certificate.verifySpkac(val), { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "spkac" argument must be one of type Buffer, TypedArray, ' + - `or DataView. Received type ${typeof val}` + message: 'The "spkac" argument must be an instance of Buffer, ' + + `TypedArray, or DataView.${common.invalidArgTypeHelper(val)}` } ); }); @@ -84,8 +84,9 @@ assert(Certificate() instanceof Certificate); [1, {}, [], Infinity, true, undefined, null].forEach((val) => { const errObj = { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "spkac" argument must be one of type string, Buffer,' + - ` TypedArray, or DataView. Received type ${typeof val}` + message: 'The "spkac" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(val) }; assert.throws(() => Certificate.exportPublicKey(val), errObj); assert.throws(() => Certificate.exportChallenge(val), errObj); diff --git a/test/parallel/test-crypto-cipher-decipher.js b/test/parallel/test-crypto-cipher-decipher.js index ce6ea4e3b81ea4..45e4bd6ea72f49 100644 --- a/test/parallel/test-crypto-cipher-decipher.js +++ b/test/parallel/test-crypto-cipher-decipher.js @@ -91,7 +91,7 @@ testCipher2(Buffer.from('0123456789abcdef')); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "cipher" argument must be of type string. ' + - 'Received type object' + 'Received null' }); common.expectsError( @@ -99,8 +99,8 @@ testCipher2(Buffer.from('0123456789abcdef')); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "password" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView. Received type object' + message: 'The "password" argument must be of type string or an instance' + + ' of Buffer, TypedArray, or DataView. Received null' }); common.expectsError( @@ -108,8 +108,8 @@ testCipher2(Buffer.from('0123456789abcdef')); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "data" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView. Received type object' + message: 'The "data" argument must be of type string or an instance' + + ' of Buffer, TypedArray, or DataView. Received null' }); common.expectsError( @@ -117,8 +117,8 @@ testCipher2(Buffer.from('0123456789abcdef')); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "buffer" argument must be one of type Buffer, ' + - 'TypedArray, or DataView. Received type object' + message: 'The "buffer" argument must be an instance' + + ' of Buffer, TypedArray, or DataView. Received null' }); } @@ -134,7 +134,7 @@ testCipher2(Buffer.from('0123456789abcdef')); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "cipher" argument must be of type string. ' + - 'Received type object' + 'Received null' }); common.expectsError( @@ -142,8 +142,8 @@ testCipher2(Buffer.from('0123456789abcdef')); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "buffer" argument must be one of type Buffer, ' + - 'TypedArray, or DataView. Received type object' + message: 'The "buffer" argument must be an instance of Buffer, ' + + 'TypedArray, or DataView. Received null' }); common.expectsError( @@ -151,8 +151,8 @@ testCipher2(Buffer.from('0123456789abcdef')); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "password" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView. Received type object' + message: 'The "password" argument must be of type string or an ' + + 'instance of Buffer, TypedArray, or DataView. Received null' }); } diff --git a/test/parallel/test-crypto-cipheriv-decipheriv.js b/test/parallel/test-crypto-cipheriv-decipheriv.js index d9cc725da1d393..d4eda6bb1fca6a 100644 --- a/test/parallel/test-crypto-cipheriv-decipheriv.js +++ b/test/parallel/test-crypto-cipheriv-decipheriv.js @@ -93,7 +93,7 @@ function testCipher3(key, iv) { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "cipher" argument must be of type string. ' + - 'Received type object' + 'Received null' }); common.expectsError( @@ -101,8 +101,8 @@ function testCipher3(key, iv) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "key" argument must be one of type Buffer, TypedArray, ' + - 'DataView, string, or KeyObject. Received type object' + message: 'The "key" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, DataView, or KeyObject. Received null' }); common.expectsError( @@ -110,8 +110,8 @@ function testCipher3(key, iv) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "iv" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView. Received type number' + message: 'The "iv" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, or DataView. Received type number (10)' }); } @@ -130,7 +130,7 @@ function testCipher3(key, iv) { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "cipher" argument must be of type string. ' + - 'Received type object' + 'Received null' }); common.expectsError( @@ -138,8 +138,8 @@ function testCipher3(key, iv) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "key" argument must be one of type Buffer, TypedArray, ' + - 'DataView, string, or KeyObject. Received type object' + message: 'The "key" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, DataView, or KeyObject. Received null' }); common.expectsError( @@ -147,8 +147,8 @@ function testCipher3(key, iv) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "iv" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView. Received type number' + message: 'The "iv" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, or DataView. Received type number (10)' }); } diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index bf991a5c34ea86..027b58b8262b2f 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -53,8 +53,9 @@ assert.strictEqual(dh2.verifyError, 0); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "sizeOrKey" argument must be one of type number, string, ' + - `Buffer, TypedArray, or DataView. Received type ${typeof input}` + message: 'The "sizeOrKey" argument must be one of type number or string' + + ' or an instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(input) } ); }); @@ -381,7 +382,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "curve" argument must be of type string. ' + - 'Received type undefined' + 'Received undefined' }); assert.throws( diff --git a/test/parallel/test-crypto-engine.js b/test/parallel/test-crypto-engine.js index ca76672de8dc95..e3ac270fef1abe 100644 --- a/test/parallel/test-crypto-engine.js +++ b/test/parallel/test-crypto-engine.js @@ -12,7 +12,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "id" argument must be of type string. Received type boolean' + message: 'The "id" argument must be of type string. Received type boolean' + + ' (true)' }); common.expectsError( @@ -20,7 +21,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "flags" argument must be of type number. Received type string' + message: 'The "flags" argument must be of type number. Received type' + + " string ('notANumber')" }); common.expectsError( diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index a0c3ffeb20ca9a..0ccc300aa25778 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -129,8 +129,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "data" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView. Received type undefined' + message: 'The "data" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, or DataView. Received undefined' }); // Default UTF-8 encoding @@ -171,7 +171,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "algorithm" argument must be of type string. ' + - 'Received type undefined' + 'Received undefined' } ); diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index 2601994ab1a433..dd7b5631042d31 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -18,7 +18,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "hmac" argument must be of type string. Received type object' + message: 'The "hmac" argument must be of type string. Received null' }); // This used to segfault. See: https://github.com/nodejs/node/issues/9819 @@ -36,8 +36,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "key" argument must be one of type Buffer, TypedArray, ' + - 'DataView, string, or KeyObject. Received type object' + message: 'The "key" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, DataView, or KeyObject. Received null' }); function testHmac(algo, key, data, expected) { diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js index dc995be041ed48..c8303431fb3051 100644 --- a/test/parallel/test-crypto-key-objects.js +++ b/test/parallel/test-crypto-key-objects.js @@ -59,7 +59,8 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', type: TypeError, code: 'ERR_INVALID_ARG_TYPE', message: - 'The "handle" argument must be of type object. Received type string' + 'The "handle" argument must be of type object. Received type ' + + "string ('')" }); } @@ -102,8 +103,9 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', common.expectsError(() => createPrivateKey(createPublicKey(privatePem)), { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "key" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView. Received type object' + message: 'The "key" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, or DataView. Received an instance of ' + + 'PublicKeyObject' }); // Similarly, passing an existing private key object to createPrivateKey @@ -112,8 +114,9 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', common.expectsError(() => createPrivateKey(privateKey), { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "key" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView. Received type object' + message: 'The "key" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, or DataView. Received an instance of ' + + 'PrivateKeyObject' }); } @@ -139,8 +142,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', common.expectsError(() => publicKey.export(opt), { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options" argument must be of type object. Received type ' + - typeof opt + message: /^The "options" argument must be of type object/ }); } diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index 8c3432e06cb647..605a3742052b34 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -598,8 +598,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); common.expectsError(() => generateKeyPairSync(type, {}), { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "type" argument must be of type string. Received type ' + - typeof type + message: 'The "type" argument must be of type string.' + + common.invalidArgTypeHelper(type) }); } @@ -615,8 +615,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); common.expectsError(() => generateKeyPair('rsa', common.mustNotCall()), { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options" argument must be of ' + - 'type object. Received type undefined' + message: 'The "options" argument must be of type object. ' + + 'Received undefined' }); // Even if no options are required, it should be impossible to pass anything @@ -624,8 +624,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); common.expectsError(() => generateKeyPair('ed448', 0, common.mustNotCall()), { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options" argument must be of ' + - 'type object. Received type number' + message: 'The "options" argument must be of type object. ' + + 'Received type number (0)' }); } diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js index 86df47f2f663ec..a6aeefad0d43de 100644 --- a/test/parallel/test-crypto-pbkdf2.js +++ b/test/parallel/test-crypto-pbkdf2.js @@ -87,8 +87,8 @@ for (const iterations of [-1, 0]) { }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "keylen" argument must be of type number. ' + - `Received type ${typeof notNumber}` + message: 'The "keylen" argument must be of type number.' + + `${common.invalidArgTypeHelper(notNumber)}` }); }); @@ -127,8 +127,8 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "digest" argument must be one of type string or null. ' + - 'Received type undefined' + message: 'The "digest" argument must be of type string or null. ' + + 'Received undefined' }); assert.throws( @@ -136,19 +136,19 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "digest" argument must be one of type string or null. ' + - 'Received type undefined' + message: 'The "digest" argument must be of type string or null. ' + + 'Received undefined' }); [1, {}, [], true, undefined, null].forEach((input) => { - const msgPart2 = 'Buffer, TypedArray, or DataView.' + - ` Received type ${typeof input}`; + const msgPart2 = 'an instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(input); assert.throws( () => crypto.pbkdf2(input, 'salt', 8, 8, 'sha256', common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "password" argument must be one of type string, ${msgPart2}` + message: `The "password" argument must be of type string or ${msgPart2}` } ); @@ -157,7 +157,7 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "salt" argument must be one of type string, ${msgPart2}` + message: `The "salt" argument must be of type string or ${msgPart2}` } ); @@ -166,7 +166,7 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "password" argument must be one of type string, ${msgPart2}` + message: `The "password" argument must be of type string or ${msgPart2}` } ); @@ -175,19 +175,19 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "salt" argument must be one of type string, ${msgPart2}` + message: `The "salt" argument must be of type string or ${msgPart2}` } ); }); ['test', {}, [], true, undefined, null].forEach((i) => { - const received = `Received type ${typeof i}`; + const received = common.invalidArgTypeHelper(i); assert.throws( () => crypto.pbkdf2('pass', 'salt', i, 8, 'sha256', common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "iterations" argument must be of type number. ${received}` + message: `The "iterations" argument must be of type number.${received}` } ); @@ -196,7 +196,7 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "iterations" argument must be of type number. ${received}` + message: `The "iterations" argument must be of type number.${received}` } ); }); diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index 1d40c8b1814d49..4650b3c8bd356f 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -46,8 +46,8 @@ common.expectWarning('DeprecationWarning', const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "size" argument must be of type number. ' + - `Received type ${typeof value}` + message: 'The "size" argument must be of type number.' + + common.invalidArgTypeHelper(value) }; assert.throws(() => f(value), errObj); assert.throws(() => f(value, common.mustNotCall()), errObj); @@ -202,7 +202,7 @@ common.expectWarning('DeprecationWarning', code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', message: 'The "offset" argument must be of type number. ' + - 'Received type string' + "Received type string ('test')" }; assert.throws(() => crypto.randomFillSync(buf, 'test'), typeErrObj); @@ -211,8 +211,7 @@ common.expectWarning('DeprecationWarning', () => crypto.randomFill(buf, 'test', common.mustNotCall()), typeErrObj); - typeErrObj.message = 'The "size" argument must be of type number. ' + - 'Received type string'; + typeErrObj.message = typeErrObj.message.replace('offset', 'size'); assert.throws(() => crypto.randomFillSync(buf, 0, 'test'), typeErrObj); assert.throws( diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index a16d25f540e1a8..d98317a3547052 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -364,18 +364,18 @@ common.expectsError( const verify = crypto.createVerify('SHA1'); [1, [], {}, undefined, null, true, Infinity].forEach((input) => { - const type = typeof input; const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "algorithm" argument must be of type string. ' + - `Received type ${type}` + message: 'The "algorithm" argument must be of type string.' + + `${common.invalidArgTypeHelper(input)}` }; assert.throws(() => crypto.createSign(input), errObj); assert.throws(() => crypto.createVerify(input), errObj); - errObj.message = 'The "data" argument must be one of type string, ' + - `Buffer, TypedArray, or DataView. Received type ${type}`; + errObj.message = 'The "data" argument must be of type string or an ' + + 'instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(input); assert.throws(() => sign.update(input), errObj); assert.throws(() => verify.update(input), errObj); assert.throws(() => sign._write(input, 'utf8', () => {}), errObj); @@ -391,19 +391,20 @@ common.expectsError( }); [1, {}, [], Infinity].forEach((input) => { - const type = typeof input; const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "key" argument must be one of type string, Buffer, ' + - `TypedArray, DataView, or KeyObject. Received type ${type}` + message: 'The "key" argument must be of type string or an instance of ' + + 'Buffer, TypedArray, DataView, or KeyObject.' + + common.invalidArgTypeHelper(input) }; assert.throws(() => sign.sign(input), errObj); assert.throws(() => verify.verify(input), errObj); - errObj.message = 'The "signature" argument must be one of type string, ' + - `Buffer, TypedArray, or DataView. Received type ${type}`; + errObj.message = 'The "signature" argument must be of type string or an ' + + 'instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(input); assert.throws(() => verify.verify('test', input), errObj); }); } @@ -477,25 +478,25 @@ common.expectsError( [1, {}, [], true, Infinity].forEach((input) => { const data = Buffer.alloc(1); const sig = Buffer.alloc(1); - const type = typeof input; + const received = common.invalidArgTypeHelper(input); const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "data" argument must be one of type Buffer, ' + - `TypedArray, or DataView. Received type ${type}` + message: 'The "data" argument must be an instance of Buffer, ' + + `TypedArray, or DataView.${received}` }; assert.throws(() => crypto.sign(null, input, 'asdf'), errObj); assert.throws(() => crypto.verify(null, input, 'asdf', sig), errObj); - errObj.message = 'The "key" argument must be one of type string, Buffer, ' + - `TypedArray, DataView, or KeyObject. Received type ${type}`; + errObj.message = 'The "key" argument must be of type string or an instance ' + + `of Buffer, TypedArray, DataView, or KeyObject.${received}`; assert.throws(() => crypto.sign(null, data, input), errObj); assert.throws(() => crypto.verify(null, data, input, sig), errObj); - errObj.message = 'The "signature" argument must be one of type ' + - `Buffer, TypedArray, or DataView. Received type ${type}`; + errObj.message = 'The "signature" argument must be an instance of ' + + `Buffer, TypedArray, or DataView.${received}`; assert.throws(() => crypto.verify(null, data, 'test', input), errObj); }); diff --git a/test/parallel/test-dgram-custom-lookup.js b/test/parallel/test-dgram-custom-lookup.js index ae623283644606..b6dc52bd0b7f78 100644 --- a/test/parallel/test-dgram-custom-lookup.js +++ b/test/parallel/test-dgram-custom-lookup.js @@ -40,8 +40,8 @@ const dns = require('dns'); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "lookup" argument must be of type Function. ' + - `Received type ${typeof value}` + message: 'The "lookup" argument must be of type function.' + + common.invalidArgTypeHelper(value) }); }); } diff --git a/test/parallel/test-dgram-multicast-setTTL.js b/test/parallel/test-dgram-multicast-setTTL.js index 2e3aad63fe3012..805b7e344b77b9 100644 --- a/test/parallel/test-dgram-multicast-setTTL.js +++ b/test/parallel/test-dgram-multicast-setTTL.js @@ -40,7 +40,8 @@ socket.on('listening', common.mustCall(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "ttl" argument must be of type number. Received type string' + message: 'The "ttl" argument must be of type number. Received type string' + + " ('foo')" }); // Close the socket diff --git a/test/parallel/test-dgram-send-address-types.js b/test/parallel/test-dgram-send-address-types.js index 7f4bcf53eb5b04..d64558bac4424e 100644 --- a/test/parallel/test-dgram-send-address-types.js +++ b/test/parallel/test-dgram-send-address-types.js @@ -26,8 +26,8 @@ const client = dgram.createSocket('udp4').bind(0, () => { const expectedError = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "address" argument must be one of type string or falsy. ' + - `Received type ${typeof invalidInput}` + message: 'The "address" argument must be of type string or falsy.' + + `${common.invalidArgTypeHelper(invalidInput)}` }; assert.throws(() => client.send(buf, port, invalidInput), expectedError); }); diff --git a/test/parallel/test-dgram-send-bad-arguments.js b/test/parallel/test-dgram-send-bad-arguments.js index f8f2a2de1368d5..644ffb3327ba05 100644 --- a/test/parallel/test-dgram-send-bad-arguments.js +++ b/test/parallel/test-dgram-send-bad-arguments.js @@ -35,8 +35,8 @@ function checkArgs(connected) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "buffer" argument must be one of type ' + - 'Buffer, Uint8Array, or string. Received type undefined' + message: 'The "buffer" argument must be of type string or an instance ' + + 'of Buffer or Uint8Array. Received undefined' } ); @@ -89,8 +89,8 @@ function checkArgs(connected) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "buffer" argument must be one of type ' + - 'Buffer, Uint8Array, or string. Received type number' + message: 'The "buffer" argument must be of type string or an instance ' + + 'of Buffer or Uint8Array. Received type number (23)' } ); @@ -100,8 +100,8 @@ function checkArgs(connected) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "buffer list arguments" argument must be one of type ' + - 'Buffer or string. Received type object' + message: 'The "buffer list arguments" argument must be of type string ' + + 'or an instance of Buffer. Received an instance of Array' } ); } diff --git a/test/parallel/test-dgram-sendto.js b/test/parallel/test-dgram-sendto.js index 6eea4894b1c1e3..967a22383fabd8 100644 --- a/test/parallel/test-dgram-sendto.js +++ b/test/parallel/test-dgram-sendto.js @@ -7,31 +7,31 @@ const socket = dgram.createSocket('udp4'); const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "offset" argument must be of type number. Received type ' + + message: 'The "offset" argument must be of type number. Received ' + 'undefined' }; assert.throws(() => socket.sendto(), errObj); errObj.message = 'The "length" argument must be of type number. Received ' + - 'type string'; + "type string ('offset')"; assert.throws( () => socket.sendto('buffer', 1, 'offset', 'port', 'address', 'cb'), errObj); errObj.message = 'The "offset" argument must be of type number. Received ' + - 'type string'; + "type string ('offset')"; assert.throws( () => socket.sendto('buffer', 'offset', 1, 'port', 'address', 'cb'), errObj); errObj.message = 'The "address" argument must be of type string. Received ' + - 'type boolean'; + 'type boolean (false)'; assert.throws( () => socket.sendto('buffer', 1, 1, 10, false, 'cb'), errObj); errObj.message = 'The "port" argument must be of type number. Received ' + - 'type boolean'; + 'type boolean (false)'; assert.throws( () => socket.sendto('buffer', 1, 1, false, 'address', 'cb'), errObj); diff --git a/test/parallel/test-dgram-setTTL.js b/test/parallel/test-dgram-setTTL.js index c6e8cb3c66923c..36af63de10134a 100644 --- a/test/parallel/test-dgram-setTTL.js +++ b/test/parallel/test-dgram-setTTL.js @@ -14,7 +14,8 @@ socket.on('listening', common.mustCall(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "ttl" argument must be of type number. Received type string' + message: 'The "ttl" argument must be of type number. Received type string' + + " ('foo')" }); // TTL must be a number from > 0 to < 256 diff --git a/test/parallel/test-dns-setservers-type-check.js b/test/parallel/test-dns-setservers-type-check.js index bdf52a32e0fa8a..9f09ee4ebf6519 100644 --- a/test/parallel/test-dns-setservers-type-check.js +++ b/test/parallel/test-dns-setservers-type-check.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const { addresses } = require('../common/internet'); const assert = require('assert'); const dns = require('dns'); @@ -20,8 +20,8 @@ const promiseResolver = new dns.promises.Resolver(); const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "servers" argument must be of type Array. Received type ' + - typeof val + message: 'The "servers" argument must be an instance of Array.' + + common.invalidArgTypeHelper(val) }; assert.throws( () => { @@ -60,8 +60,8 @@ const promiseResolver = new dns.promises.Resolver(); const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "servers[0]" argument must be of type string. ' + - `Received type ${typeof val[0]}` + message: 'The "servers[0]" argument must be of type string.' + + common.invalidArgTypeHelper(val[0]) }; assert.throws( () => { diff --git a/test/parallel/test-dns.js b/test/parallel/test-dns.js index e854574a2eaba5..d9143f52d33e77 100644 --- a/test/parallel/test-dns.js +++ b/test/parallel/test-dns.js @@ -144,7 +144,7 @@ assert.deepStrictEqual(dns.getServers(), []); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "rrtype" argument must be of type string. ' + - 'Received type object' + 'Received an instance of Array' }; common.expectsError(() => { dns.resolve('example.com', [], common.mustNotCall()); @@ -158,7 +158,7 @@ assert.deepStrictEqual(dns.getServers(), []); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "name" argument must be of type string. ' + - 'Received type undefined' + 'Received undefined' }; common.expectsError(() => { dnsPromises.resolve(); @@ -170,7 +170,7 @@ assert.deepStrictEqual(dns.getServers(), []); const errorReg = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /^The "hostname" argument must be of type string\. Received type .*/ + message: /^The "hostname" argument must be of type string\. Received .*/ }, 10); assert.throws(() => dns.lookup({}, common.mustNotCall()), errorReg); diff --git a/test/parallel/test-event-emitter-add-listeners.js b/test/parallel/test-event-emitter-add-listeners.js index 7812de670ff5fb..d7ebf424380c4b 100644 --- a/test/parallel/test-event-emitter-add-listeners.js +++ b/test/parallel/test-event-emitter-add-listeners.js @@ -92,6 +92,6 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "listener" argument must be of type Function. ' + - 'Received type object' + message: 'The "listener" argument must be of type function. ' + + 'Received null' }); diff --git a/test/parallel/test-event-emitter-once.js b/test/parallel/test-event-emitter-once.js index 1bdf0cbf126aaf..5b74185b12c453 100644 --- a/test/parallel/test-event-emitter-once.js +++ b/test/parallel/test-event-emitter-once.js @@ -56,8 +56,8 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "listener" argument must be of type Function. ' + - 'Received type object' + message: 'The "listener" argument must be of type function. ' + + 'Received null' }); { diff --git a/test/parallel/test-event-emitter-prepend.js b/test/parallel/test-event-emitter-prepend.js index c5cf009259d722..21f381af85fa1d 100644 --- a/test/parallel/test-event-emitter-prepend.js +++ b/test/parallel/test-event-emitter-prepend.js @@ -25,8 +25,8 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "listener" argument must be of type Function. ' + - 'Received type object' + message: 'The "listener" argument must be of type function. ' + + 'Received null' }); // Test fallback if prependListener is undefined. diff --git a/test/parallel/test-event-emitter-remove-listeners.js b/test/parallel/test-event-emitter-remove-listeners.js index 8b9d6215601e9d..97ae403ddd25b0 100644 --- a/test/parallel/test-event-emitter-remove-listeners.js +++ b/test/parallel/test-event-emitter-remove-listeners.js @@ -151,8 +151,8 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "listener" argument must be of type Function. ' + - 'Received type object' + message: 'The "listener" argument must be of type function. ' + + 'Received null' }); { diff --git a/test/parallel/test-fs-buffer.js b/test/parallel/test-fs-buffer.js index 1e898d3891339a..bad5adea448f0b 100644 --- a/test/parallel/test-fs-buffer.js +++ b/test/parallel/test-fs-buffer.js @@ -25,8 +25,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "path" argument must be one of type string, Buffer, or URL.' + - ' Received type boolean' + message: 'The "path" argument must be of type string or an instance of ' + + 'Buffer or URL. Received type boolean (true)' } ); diff --git a/test/parallel/test-fs-chmod.js b/test/parallel/test-fs-chmod.js index cc8caf86fd3c22..8314c6f73daaf0 100644 --- a/test/parallel/test-fs-chmod.js +++ b/test/parallel/test-fs-chmod.js @@ -151,8 +151,9 @@ if (fs.lchmod) { const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "path" argument must be one of type string, Buffer, or URL.' + - ` Received type ${typeof input}` + message: 'The "path" argument must be of type string or an instance ' + + 'of Buffer or URL.' + + common.invalidArgTypeHelper(input) }; assert.throws(() => fs.chmod(input, 1, common.mustNotCall()), errObj); assert.throws(() => fs.chmodSync(input, 1), errObj); diff --git a/test/parallel/test-fs-close-errors.js b/test/parallel/test-fs-close-errors.js index 6168d5c20ab8e5..52930a203eddbb 100644 --- a/test/parallel/test-fs-close-errors.js +++ b/test/parallel/test-fs-close-errors.js @@ -3,7 +3,7 @@ // This tests that the errors thrown from fs.close and fs.closeSync // include the desired properties -require('../common'); +const common = require('../common'); const assert = require('assert'); const fs = require('fs'); @@ -11,8 +11,8 @@ const fs = require('fs'); const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "fd" argument must be of type number. ' + - `Received type ${typeof input}` + message: 'The "fd" argument must be of type number.' + + common.invalidArgTypeHelper(input) }; assert.throws(() => fs.close(input), errObj); assert.throws(() => fs.closeSync(input), errObj); diff --git a/test/parallel/test-fs-fchmod.js b/test/parallel/test-fs-fchmod.js index ebbc2792e137e6..a6d5c0c95dac1b 100644 --- a/test/parallel/test-fs-fchmod.js +++ b/test/parallel/test-fs-fchmod.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const util = require('util'); const fs = require('fs'); @@ -12,8 +12,8 @@ const fs = require('fs'); const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "fd" argument must be of type number. Received type ' + - typeof input + message: 'The "fd" argument must be of type number.' + + common.invalidArgTypeHelper(input) }; assert.throws(() => fs.fchmod(input), errObj); assert.throws(() => fs.fchmodSync(input), errObj); diff --git a/test/parallel/test-fs-fchown.js b/test/parallel/test-fs-fchown.js index 4872e550dba37f..cf28d54e9d9679 100644 --- a/test/parallel/test-fs-fchown.js +++ b/test/parallel/test-fs-fchown.js @@ -23,13 +23,10 @@ function testGid(input, errObj) { const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "fd" argument must be of type number. Received type ' + - typeof input + message: /fd|uid|gid/ }; testFd(input, errObj); - errObj.message = errObj.message.replace('fd', 'uid'); testUid(input, errObj); - errObj.message = errObj.message.replace('uid', 'gid'); testGid(input, errObj); }); diff --git a/test/parallel/test-fs-fsync.js b/test/parallel/test-fs-fsync.js index 28a513d10f2d29..70027e33ed9e0a 100644 --- a/test/parallel/test-fs-fsync.js +++ b/test/parallel/test-fs-fsync.js @@ -54,9 +54,7 @@ fs.open(fileTemp, 'a', 0o777, common.mustCall(function(err, fd) { ['', false, null, undefined, {}, []].forEach((input) => { const errObj = { code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: 'The "fd" argument must be of type number. Received type ' + - typeof input + name: 'TypeError' }; assert.throws(() => fs.fdatasync(input), errObj); assert.throws(() => fs.fdatasyncSync(input), errObj); diff --git a/test/parallel/test-fs-mkdir.js b/test/parallel/test-fs-mkdir.js index 2cd42f65669e90..5e9a2bd75ea2a3 100644 --- a/test/parallel/test-fs-mkdir.js +++ b/test/parallel/test-fs-mkdir.js @@ -217,13 +217,14 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) { { const pathname = path.join(tmpdir.path, nextdir()); ['', 1, {}, [], null, Symbol('test'), () => {}].forEach((recursive) => { + const received = common.invalidArgTypeHelper(recursive); common.expectsError( () => fs.mkdir(pathname, { recursive }, common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "recursive" argument must be of type boolean. Received ' + - `type ${typeof recursive}` + message: 'The "recursive" argument must be of type boolean.' + + received } ); common.expectsError( @@ -231,8 +232,8 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "recursive" argument must be of type boolean. Received ' + - `type ${typeof recursive}` + message: 'The "recursive" argument must be of type boolean.' + + received } ); }); diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index 3c7903c98f04d2..a5ced6970597b0 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -363,9 +363,7 @@ async function getHandle(dest) { async () => mkdir(dir, { recursive }), { code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: 'The "recursive" argument must be of type boolean. ' + - `Received type ${typeof recursive}` + name: 'TypeError' } ); }); diff --git a/test/parallel/test-fs-read-type.js b/test/parallel/test-fs-read-type.js index f5ac78a23026fd..dbe036794ceb56 100644 --- a/test/parallel/test-fs-read-type.js +++ b/test/parallel/test-fs-read-type.js @@ -15,8 +15,8 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "buffer" argument must be one of type Buffer, TypedArray, ' + - 'or DataView. Received type number' + message: 'The "buffer" argument must be an instance of Buffer, ' + + 'TypedArray, or DataView. Received type number (4)' } ); @@ -30,9 +30,7 @@ assert.throws( common.mustNotCall()); }, { code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: 'The "fd" argument must be of type number. ' + - `Received type ${typeof value}` + name: 'TypeError' }); }); @@ -84,8 +82,8 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "buffer" argument must be one of type Buffer, TypedArray, ' + - 'or DataView. Received type number' + message: 'The "buffer" argument must be an instance of Buffer, ' + + 'TypedArray, or DataView. Received type number (4)' } ); @@ -98,9 +96,7 @@ assert.throws( 0); }, { code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: 'The "fd" argument must be of type number. ' + - `Received type ${typeof value}` + name: 'TypeError' }); }); diff --git a/test/parallel/test-fs-read.js b/test/parallel/test-fs-read.js index e6fe6231ffd9ec..03ddf7f36d1f98 100644 --- a/test/parallel/test-fs-read.js +++ b/test/parallel/test-fs-read.js @@ -83,7 +83,7 @@ assert.throws( assert.throws( () => fs.read(null, Buffer.alloc(1), 0, 1, 0), { - message: 'The "fd" argument must be of type number. Received type object', + message: 'The "fd" argument must be of type number. Received null', code: 'ERR_INVALID_ARG_TYPE', } ); diff --git a/test/parallel/test-fs-readfile-error.js b/test/parallel/test-fs-readfile-error.js index 3b245058ff6f38..4f0aaf888db793 100644 --- a/test/parallel/test-fs-readfile-error.js +++ b/test/parallel/test-fs-readfile-error.js @@ -60,8 +60,8 @@ common.expectsError( () => { fs.readFile(() => {}, common.mustNotCall()); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "path" argument must be one of type string, Buffer, or URL.' + - ' Received type function', + message: 'The "path" argument must be of type string or an instance of ' + + 'Buffer or URL. Received type function ([Function (anonymous)])', type: TypeError } ); diff --git a/test/parallel/test-fs-rename-type-check.js b/test/parallel/test-fs-rename-type-check.js index bc1277740fd514..09004dcb623b6c 100644 --- a/test/parallel/test-fs-rename-type-check.js +++ b/test/parallel/test-fs-rename-type-check.js @@ -5,13 +5,14 @@ const assert = require('assert'); const fs = require('fs'); [false, 1, [], {}, null, undefined].forEach((input) => { - const type = `of type string, Buffer, or URL. Received type ${typeof input}`; + const type = 'of type string or an instance of Buffer or URL.' + + common.invalidArgTypeHelper(input); assert.throws( () => fs.rename(input, 'does-not-exist', common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "oldPath" argument must be one ${type}` + message: `The "oldPath" argument must be ${type}` } ); assert.throws( @@ -19,7 +20,7 @@ const fs = require('fs'); { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "newPath" argument must be one ${type}` + message: `The "newPath" argument must be ${type}` } ); assert.throws( @@ -27,7 +28,7 @@ const fs = require('fs'); { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "oldPath" argument must be one ${type}` + message: `The "oldPath" argument must be ${type}` } ); assert.throws( @@ -35,7 +36,7 @@ const fs = require('fs'); { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: `The "newPath" argument must be one ${type}` + message: `The "newPath" argument must be ${type}` } ); }); diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index bde3e06765cbb8..32acf65b7b96a3 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -116,9 +116,7 @@ fs.stat(__filename, common.mustCall(function(err, s) { () => fs[fnName](input), { code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: 'The "fd" argument must be of type number. ' + - `Received type ${typeof input}` + name: 'TypeError' } ); }); diff --git a/test/parallel/test-fs-symlink.js b/test/parallel/test-fs-symlink.js index c52ffbc105ffae..d1784fdd3a07f4 100644 --- a/test/parallel/test-fs-symlink.js +++ b/test/parallel/test-fs-symlink.js @@ -74,13 +74,11 @@ fs.symlink(linkData, linkPath, common.mustCall(function(err) { const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "target" argument must be one of type string, Buffer, or ' + - `URL. Received type ${typeof input}` + message: /target|path/ }; assert.throws(() => fs.symlink(input, '', common.mustNotCall()), errObj); assert.throws(() => fs.symlinkSync(input, ''), errObj); - errObj.message = errObj.message.replace('target', 'path'); assert.throws(() => fs.symlink('', input, common.mustNotCall()), errObj); assert.throws(() => fs.symlinkSync('', input), errObj); }); diff --git a/test/parallel/test-fs-truncate.js b/test/parallel/test-fs-truncate.js index 044ff622bdb129..c41f31376f2adb 100644 --- a/test/parallel/test-fs-truncate.js +++ b/test/parallel/test-fs-truncate.js @@ -179,13 +179,13 @@ function testFtruncate(cb) { process.on('beforeExit', () => fs.closeSync(fd)); ['', false, null, {}, []].forEach((input) => { + const received = common.invalidArgTypeHelper(input); assert.throws( () => fs.truncate(file5, input, common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "len" argument must be of type number. ' + - `Received type ${typeof input}` + message: `The "len" argument must be of type number.${received}` } ); @@ -194,8 +194,7 @@ function testFtruncate(cb) { { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "len" argument must be of type number. ' + - `Received type ${typeof input}` + message: `The "len" argument must be of type number.${received}` } ); }); @@ -268,8 +267,8 @@ function testFtruncate(cb) { { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "len" argument must be of type number. ' + - `Received type ${typeof input}` + message: 'The "len" argument must be of type number.' + + common.invalidArgTypeHelper(input) } ); }); @@ -281,8 +280,8 @@ function testFtruncate(cb) { { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "fd" argument must be of type number. ' + - `Received type ${typeof input}` + message: 'The "fd" argument must be of type number.' + + common.invalidArgTypeHelper(input) } ); }); diff --git a/test/parallel/test-fs-watch.js b/test/parallel/test-fs-watch.js index fb674bbfeab4c5..ea24f406cc0672 100644 --- a/test/parallel/test-fs-watch.js +++ b/test/parallel/test-fs-watch.js @@ -89,9 +89,7 @@ for (const testCase of cases) { () => fs.watch(input, common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "filename" argument must be one of type string, Buffer, ' + - `or URL. Received type ${typeof input}` + type: TypeError } ); }); diff --git a/test/parallel/test-http-client-check-http-token.js b/test/parallel/test-http-client-check-http-token.js index 828d7fa79a503c..5a5ec2fb95f148 100644 --- a/test/parallel/test-http-client-check-http-token.js +++ b/test/parallel/test-http-client-check-http-token.js @@ -22,8 +22,8 @@ server.listen(0, common.mustCall(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "method" argument must be of type string. ' + - `Received type ${typeof method}` + message: 'The "method" argument must be of type string.' + + common.invalidArgTypeHelper(method) }); }); diff --git a/test/parallel/test-http-client-reject-unexpected-agent.js b/test/parallel/test-http-client-reject-unexpected-agent.js index 27cb77951cf5fd..664fb493102229 100644 --- a/test/parallel/test-http-client-reject-unexpected-agent.js +++ b/test/parallel/test-http-client-reject-unexpected-agent.js @@ -52,8 +52,9 @@ server.listen(0, baseOptions.host, common.mustCall(function() { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.agent" property must be one of type Agent-like' + - ` Object, undefined, or false. Received type ${typeof agent}` + message: 'The "options.agent" property must be one of Agent-like ' + + 'Object, undefined, or false.' + + common.invalidArgTypeHelper(agent) } ); }); diff --git a/test/parallel/test-http-hostname-typechecking.js b/test/parallel/test-http-hostname-typechecking.js index 72440391fa2938..6ec6b7d6271aa7 100644 --- a/test/parallel/test-http-hostname-typechecking.js +++ b/test/parallel/test-http-hostname-typechecking.js @@ -8,14 +8,15 @@ const http = require('http'); const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()]; vals.forEach((v) => { + const received = common.invalidArgTypeHelper(v); common.expectsError( () => http.request({ hostname: v }), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.hostname" property must be one of ' + - 'type string, undefined, or null. ' + - `Received type ${typeof v}` + message: 'The "options.hostname" property must be of ' + + 'type string or one of undefined or null.' + + received } ); @@ -24,9 +25,9 @@ vals.forEach((v) => { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.host" property must be one of ' + - 'type string, undefined, or null. ' + - `Received type ${typeof v}` + message: 'The "options.host" property must be of ' + + 'type string or one of undefined or null.' + + received } ); }); diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js index 0ff05f234c2c5d..b4e4018e1d0bd4 100644 --- a/test/parallel/test-http-mutable-headers.js +++ b/test/parallel/test-http-mutable-headers.js @@ -72,7 +72,7 @@ const s = http.createServer(common.mustCall((req, res) => { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "name" argument must be of type string. ' + - 'Received type undefined' + 'Received undefined' } ); common.expectsError( @@ -81,7 +81,7 @@ const s = http.createServer(common.mustCall((req, res) => { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "name" argument must be of type string. ' + - 'Received type undefined' + 'Received undefined' } ); @@ -124,8 +124,8 @@ const s = http.createServer(common.mustCall((req, res) => { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "name" argument must be of type string. ' + - `Received type ${typeof val}` + message: 'The "name" argument must be of type string.' + + common.invalidArgTypeHelper(val) } ); }); diff --git a/test/parallel/test-http-outgoing-proto.js b/test/parallel/test-http-outgoing-proto.js index 0070f5399470e0..0f428b9546bd80 100644 --- a/test/parallel/test-http-outgoing-proto.js +++ b/test/parallel/test-http-outgoing-proto.js @@ -79,8 +79,8 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The first argument must be one of type string or Buffer. ' + - 'Received type undefined' + message: 'The first argument must be of type string or an instance of ' + + 'Buffer. Received undefined' }); common.expectsError(() => { @@ -89,8 +89,8 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The first argument must be one of type string or Buffer. ' + - 'Received type number' + message: 'The first argument must be of type string or an instance of ' + + 'Buffer. Received type number (1)' }); // addTrailers() diff --git a/test/parallel/test-http2-client-setNextStreamID-errors.js b/test/parallel/test-http2-client-setNextStreamID-errors.js index 203b552ef7f7f1..d13d685b3e508f 100644 --- a/test/parallel/test-http2-client-setNextStreamID-errors.js +++ b/test/parallel/test-http2-client-setNextStreamID-errors.js @@ -48,8 +48,8 @@ server.listen(0, common.mustCall(() => { { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "id" argument must be of type number. Received type ' + - typeof value + message: 'The "id" argument must be of type number.' + + common.invalidArgTypeHelper(value) } ); }); diff --git a/test/parallel/test-http2-compat-serverrequest-headers.js b/test/parallel/test-http2-compat-serverrequest-headers.js index 8b38ab147f3d25..06f37c8a47ce19 100644 --- a/test/parallel/test-http2-compat-serverrequest-headers.js +++ b/test/parallel/test-http2-compat-serverrequest-headers.js @@ -59,7 +59,7 @@ server.listen(0, common.mustCall(function() { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', message: 'The "method" argument must be of type string. ' + - 'Received type boolean' + 'Received type boolean (true)' } ); diff --git a/test/parallel/test-http2-compat-serverresponse-headers.js b/test/parallel/test-http2-compat-serverresponse-headers.js index c47de48b6a2c88..82b81a3d3fbbb6 100644 --- a/test/parallel/test-http2-compat-serverresponse-headers.js +++ b/test/parallel/test-http2-compat-serverresponse-headers.js @@ -48,7 +48,7 @@ server.listen(0, common.mustCall(function() { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', message: 'The "name" argument must be of type string. Received ' + - 'type undefined' + 'undefined' } ); }); @@ -86,7 +86,7 @@ server.listen(0, common.mustCall(function() { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "name" argument must be of type string. Received type ' + + message: 'The "name" argument must be of type string. Received ' + 'undefined' } ); diff --git a/test/parallel/test-http2-compat-serverresponse-trailers.js b/test/parallel/test-http2-compat-serverresponse-trailers.js index fe722c84ee782a..ca148ff0070026 100644 --- a/test/parallel/test-http2-compat-serverresponse-trailers.js +++ b/test/parallel/test-http2-compat-serverresponse-trailers.js @@ -44,7 +44,7 @@ server.listen(0, common.mustCall(() => { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "name" argument must be of type string. Received type ' + + message: 'The "name" argument must be of type string. Received ' + 'undefined' } ); diff --git a/test/parallel/test-http2-createsecureserver-options.js b/test/parallel/test-http2-createsecureserver-options.js index 84d75e23b334ec..269239fcf2874e 100644 --- a/test/parallel/test-http2-createsecureserver-options.js +++ b/test/parallel/test-http2-createsecureserver-options.js @@ -15,8 +15,8 @@ invalidOptions.forEach((invalidOption) => { { name: 'TypeError', code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options" argument must be of type Object. Received ' + - `type ${typeof invalidOption}` + message: 'The "options" argument must be of type object.' + + common.invalidArgTypeHelper(invalidOption) } ); }); @@ -28,8 +28,8 @@ invalidOptions.forEach((invalidSettingsOption) => { { name: 'TypeError', code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options.settings" property must be of type Object. ' + - `Received type ${typeof invalidSettingsOption}` + message: 'The "options.settings" property must be of type object.' + + common.invalidArgTypeHelper(invalidSettingsOption) } ); }); diff --git a/test/parallel/test-http2-createserver-options.js b/test/parallel/test-http2-createserver-options.js index 6f3d4b56933169..8814e2db9e8828 100644 --- a/test/parallel/test-http2-createserver-options.js +++ b/test/parallel/test-http2-createserver-options.js @@ -15,8 +15,8 @@ invalidOptions.forEach((invalidOption) => { { name: 'TypeError', code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options" argument must be of type Object. Received ' + - `type ${typeof invalidOption}` + message: 'The "options" argument must be of type object.' + + common.invalidArgTypeHelper(invalidOption) } ); }); @@ -28,8 +28,8 @@ invalidOptions.forEach((invalidSettingsOption) => { { name: 'TypeError', code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options.settings" property must be of type Object. ' + - `Received type ${typeof invalidSettingsOption}` + message: 'The "options.settings" property must be of type object.' + + common.invalidArgTypeHelper(invalidSettingsOption) } ); }); diff --git a/test/parallel/test-http2-getpackedsettings.js b/test/parallel/test-http2-getpackedsettings.js index 341cfb4fc799f2..8eca10cf49f4e3 100644 --- a/test/parallel/test-http2-getpackedsettings.js +++ b/test/parallel/test-http2-getpackedsettings.js @@ -107,8 +107,8 @@ http2.getPackedSettings({ enablePush: false }); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "buf" argument must be one of type Buffer, TypedArray, or ' + - `DataView. Received type ${typeof input}` + 'The "buf" argument must be an instance of Buffer, TypedArray, or ' + + `DataView.${common.invalidArgTypeHelper(input)}` }); }); diff --git a/test/parallel/test-http2-invalidargtypes-errors.js b/test/parallel/test-http2-invalidargtypes-errors.js index d7c451569e273d..b94a670a1a3c28 100644 --- a/test/parallel/test-http2-invalidargtypes-errors.js +++ b/test/parallel/test-http2-invalidargtypes-errors.js @@ -14,7 +14,7 @@ server.on('stream', common.mustCall((stream) => { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "code" argument must be of type number. ' + - 'Received type string' + "Received type string ('string')" } ); stream.respond(); diff --git a/test/parallel/test-http2-misc-util.js b/test/parallel/test-http2-misc-util.js index 14dc4a536617df..ec9c65ec088bb8 100644 --- a/test/parallel/test-http2-misc-util.js +++ b/test/parallel/test-http2-misc-util.js @@ -35,7 +35,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "test" argument must be of type Object. Received type string' + message: 'The "test" argument must be of type object. Received ' + + "type string ('foo')" }); common.expectsError( @@ -43,7 +44,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "test" argument must be of type Date. Received type string' + message: 'The "test" argument must be an instance of Date. Received type ' + + "string ('foo')" }); assertIsObject({}, 'test'); diff --git a/test/parallel/test-http2-ping.js b/test/parallel/test-http2-ping.js index 993867bb21c6f2..27bfd19c6f08df 100644 --- a/test/parallel/test-http2-ping.js +++ b/test/parallel/test-http2-ping.js @@ -88,8 +88,9 @@ server.listen(0, common.mustCall(() => { { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "payload" argument must be one of type Buffer, ' + - `TypedArray, or DataView. Received type ${typeof payload}` + message: 'The "payload" argument must be an instance of Buffer, ' + + 'TypedArray, or DataView.' + + common.invalidArgTypeHelper(payload) } ) ); diff --git a/test/parallel/test-http2-respond-file-fd-errors.js b/test/parallel/test-http2-respond-file-fd-errors.js index 5de21e7855eac1..06e5f6161dbd70 100644 --- a/test/parallel/test-http2-respond-file-fd-errors.js +++ b/test/parallel/test-http2-respond-file-fd-errors.js @@ -42,9 +42,8 @@ server.on('stream', common.mustCall((stream) => { { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "fd" argument must be one of type number or FileHandle.' + - ' Received type ' + - typeof types[type] + message: 'The "fd" argument must be of type number or an instance of' + + ` FileHandle.${common.invalidArgTypeHelper(types[type])}` } ); }); diff --git a/test/parallel/test-http2-server-shutdown-options-errors.js b/test/parallel/test-http2-server-shutdown-options-errors.js index 9dde6660ea25ce..0109a147aaa81f 100644 --- a/test/parallel/test-http2-server-shutdown-options-errors.js +++ b/test/parallel/test-http2-server-shutdown-options-errors.js @@ -19,13 +19,14 @@ server.on('stream', common.mustCall((stream) => { const session = stream.session; types.forEach((input) => { + const received = common.invalidArgTypeHelper(input); common.expectsError( () => session.goaway(input), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "code" argument must be of type number. Received type ' + - typeof input + message: 'The "code" argument must be of type number.' + + received } ); common.expectsError( @@ -33,8 +34,8 @@ server.on('stream', common.mustCall((stream) => { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "lastStreamID" argument must be of type number. ' + - `Received type ${typeof input}` + message: 'The "lastStreamID" argument must be of type number.' + + received } ); common.expectsError( @@ -42,8 +43,8 @@ server.on('stream', common.mustCall((stream) => { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "opaqueData" argument must be one of type Buffer, ' + - `TypedArray, or DataView. Received type ${typeof input}` + message: 'The "opaqueData" argument must be an instance of Buffer, ' + + `TypedArray, or DataView.${received}` } ); }); diff --git a/test/parallel/test-http2-timeouts.js b/test/parallel/test-http2-timeouts.js index 323e6bdd24e48a..be41f2020250d6 100644 --- a/test/parallel/test-http2-timeouts.js +++ b/test/parallel/test-http2-timeouts.js @@ -21,7 +21,8 @@ server.on('stream', common.mustCall((stream) => { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "msecs" argument must be of type number. Received type string' + 'The "msecs" argument must be of type number. Received type string' + + " ('100')" } ); common.expectsError( diff --git a/test/parallel/test-http2-util-asserts.js b/test/parallel/test-http2-util-asserts.js index 136c76cc049cdd..e80f7128378ece 100644 --- a/test/parallel/test-http2-util-asserts.js +++ b/test/parallel/test-http2-util-asserts.js @@ -26,12 +26,13 @@ const { [], [{}] ].forEach((input) => { - common.expectsError(() => assertIsObject(input, 'foo', 'Object'), - { - code: 'ERR_INVALID_ARG_TYPE', - message: 'The "foo" argument must be of type Object. ' + - `Received type ${typeof input}` - }); + common.expectsError( + () => assertIsObject(input, 'foo', 'Object'), + { + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "foo" argument must be of type object.' + + common.invalidArgTypeHelper(input) + }); }); assertWithinRange('foo', 1, 0, 2); diff --git a/test/parallel/test-https-options-boolean-check.js b/test/parallel/test-https-options-boolean-check.js index 295082e1cee109..65a17f9f7605b0 100644 --- a/test/parallel/test-https-options-boolean-check.js +++ b/test/parallel/test-https-options-boolean-check.js @@ -75,21 +75,22 @@ const caArrDataView = toDataView(caCert); [true, certDataView], [true, false], [true, false], - [{ pem: keyBuff }, false, 'pem'], + [{ pem: keyBuff }, false], [1, false], [[keyBuff, true], [certBuff, certBuff2], 1], [[true, keyStr2], [certStr, certStr2], 0], [[true, false], [certBuff, certBuff2], 0], [true, [certBuff, certBuff2]] ].forEach(([key, cert, index]) => { - const type = typeof (index === undefined ? key : key[index]); + const val = index === undefined ? key : key[index]; assert.throws(() => { https.createServer({ key, cert }); }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "options.key" property must be one of type string, Buffer, ' + - `TypedArray, or DataView. Received type ${type}` + message: 'The "options.key" property must be of type string or an ' + + 'instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(val) }); }); @@ -100,21 +101,22 @@ const caArrDataView = toDataView(caCert); [keyDataView, true], [true, true], [false, true], - [false, { pem: keyBuff }, 'pem'], + [false, { pem: keyBuff }], [false, 1], [[keyBuff, keyBuff2], [true, certBuff2], 0], [[keyStr, keyStr2], [certStr, true], 1], [[keyStr, keyStr2], [true, false], 0], [[keyStr, keyStr2], true], ].forEach(([key, cert, index]) => { - const type = typeof (index === undefined ? cert : cert[index]); + const val = index === undefined ? cert : cert[index]; assert.throws(() => { https.createServer({ key, cert }); }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "options.cert" property must be one of type string, Buffer,' + - ` TypedArray, or DataView. Received type ${type}` + message: 'The "options.cert" property must be of type string or an ' + + 'instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(val) }); }); @@ -141,13 +143,14 @@ const caArrDataView = toDataView(caCert); [keyBuff, certBuff, true], [keyBuff, certBuff, [caCert, true], 1] ].forEach(([key, cert, ca, index]) => { - const type = typeof (index ? ca[index] : ca); + const val = index === undefined ? ca : ca[index]; assert.throws(() => { https.createServer({ key, cert, ca }); }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "options.ca" property must be one of type string, Buffer, ' + - `TypedArray, or DataView. Received type ${type}` + message: 'The "options.ca" property must be of type string or an instance' + + ' of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(val) }); }); diff --git a/test/parallel/test-icu-transcode.js b/test/parallel/test-icu-transcode.js index 0b44c7795e5b15..ec28d37bf7e06b 100644 --- a/test/parallel/test-icu-transcode.js +++ b/test/parallel/test-icu-transcode.js @@ -46,8 +46,8 @@ common.expectsError( { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "source" argument must be one of type Buffer ' + - 'or Uint8Array. Received type object' + message: 'The "source" argument must be an instance of Buffer ' + + 'or Uint8Array. Received null' } ); diff --git a/test/parallel/test-internal-module-map-asserts.js b/test/parallel/test-internal-module-map-asserts.js index 614da43aba0acb..6f985faccd92bb 100644 --- a/test/parallel/test-internal-module-map-asserts.js +++ b/test/parallel/test-internal-module-map-asserts.js @@ -1,18 +1,18 @@ // Flags: --expose-internals 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const ModuleMap = require('internal/modules/esm/module_map'); // ModuleMap.get, ModuleMap.has and ModuleMap.set should only accept string // values as url argument. { - const errorReg = common.expectsError({ + const errorObj = { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, + name: 'TypeError', message: /^The "url" argument must be of type string/ - }, 12); + }; const moduleMap = new ModuleMap(); @@ -22,23 +22,21 @@ const ModuleMap = require('internal/modules/esm/module_map'); const job = undefined; [{}, [], true, 1].forEach((value) => { - assert.throws(() => moduleMap.get(value), errorReg); - assert.throws(() => moduleMap.has(value), errorReg); - assert.throws(() => moduleMap.set(value, job), errorReg); + assert.throws(() => moduleMap.get(value), errorObj); + assert.throws(() => moduleMap.has(value), errorObj); + assert.throws(() => moduleMap.set(value, job), errorObj); }); } // ModuleMap.set, job argument should only accept ModuleJob values. { - const errorReg = common.expectsError({ - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: /^The "job" argument must be of type ModuleJob/ - }, 4); - const moduleMap = new ModuleMap(); [{}, [], true, 1].forEach((value) => { - assert.throws(() => moduleMap.set('', value), errorReg); + assert.throws(() => moduleMap.set('', value), { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: /^The "job" argument must be an instance of ModuleJob/ + }); }); } diff --git a/test/parallel/test-module-loading-error.js b/test/parallel/test-module-loading-error.js index 40b6de72a3299b..24a2a8cc9fad01 100644 --- a/test/parallel/test-module-loading-error.js +++ b/test/parallel/test-module-loading-error.js @@ -60,7 +60,7 @@ assert.throws( } ); -const re = /^The "id" argument must be of type string\. Received type \w+$/; +const re = /^The "id" argument must be of type string\. Received /; [1, false, null, undefined, {}].forEach((value) => { common.expectsError( () => { require(value); }, diff --git a/test/parallel/test-net-write-arguments.js b/test/parallel/test-net-write-arguments.js index 19b037ee0fc94c..cd502202baaf3f 100644 --- a/test/parallel/test-net-write-arguments.js +++ b/test/parallel/test-net-write-arguments.js @@ -27,7 +27,7 @@ common.expectsError(() => socket.write(null), socket.write(value, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "chunk" argument must be one of type string or Buffer. ' + - `Received type ${typeof value}` + message: 'The "chunk" argument must be of type string or an instance of ' + + `Buffer.${common.invalidArgTypeHelper(value)}` })); }); diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index 901bdb0b93de63..9d616d0c130c20 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -220,8 +220,8 @@ function checkFormat(path, testCases) { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "pathObject" argument must be of type Object. ' + - `Received type ${typeof pathObject}` + message: 'The "pathObject" argument must be of type object.' + + common.invalidArgTypeHelper(pathObject) }); }); } diff --git a/test/parallel/test-performance-function.js b/test/parallel/test-performance-function.js index 25e3db639030ba..5271f419a3e34b 100644 --- a/test/parallel/test-performance-function.js +++ b/test/parallel/test-performance-function.js @@ -65,8 +65,7 @@ const { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "fn" argument must be of type ' + - `Function. Received type ${typeof input}` + message: /The "fn" argument must be of type function/ }); }); } diff --git a/test/parallel/test-performanceobserver.js b/test/parallel/test-performanceobserver.js index 75097cb8c77141..6c28baa82f1877 100644 --- a/test/parallel/test-performanceobserver.js +++ b/test/parallel/test-performanceobserver.js @@ -48,8 +48,8 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type Object. ' + - `Received type ${typeof input}` + message: 'The "options" argument must be of type object.' + + common.invalidArgTypeHelper(input) }); }); diff --git a/test/parallel/test-process-cpuUsage.js b/test/parallel/test-process-cpuUsage.js index 76e0702b9e4dc5..ecd782f86a52a9 100644 --- a/test/parallel/test-process-cpuUsage.js +++ b/test/parallel/test-process-cpuUsage.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const result = process.cpuUsage(); @@ -39,7 +39,7 @@ assert.throws( code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', message: 'The "prevValue" argument must be of type object. ' + - 'Received type number' + 'Received type number (1)' } ); @@ -54,8 +54,8 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "prevValue.user" property must be of type number. ' + - `Received type ${typeof value.user}` + message: 'The "prevValue.user" property must be of type number.' + + common.invalidArgTypeHelper(value.user) } ); }); @@ -69,8 +69,8 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "prevValue.system" property must be of type number. ' + - `Received type ${typeof value.system}` + message: 'The "prevValue.system" property must be of type number.' + + common.invalidArgTypeHelper(value.system) } ); }); diff --git a/test/parallel/test-process-euid-egid.js b/test/parallel/test-process-euid-egid.js index b9e0630dab5eca..33d630b34dd0f6 100644 --- a/test/parallel/test-process-euid-egid.js +++ b/test/parallel/test-process-euid-egid.js @@ -19,7 +19,7 @@ assert.throws(() => { }, { code: 'ERR_INVALID_ARG_TYPE', message: 'The "id" argument must be one of type number or string. ' + - 'Received type object' + 'Received an instance of Object' }); assert.throws(() => { diff --git a/test/parallel/test-process-exception-capture-errors.js b/test/parallel/test-process-exception-capture-errors.js index d2f5b8617725f4..5f89852b6e1875 100644 --- a/test/parallel/test-process-exception-capture-errors.js +++ b/test/parallel/test-process-exception-capture-errors.js @@ -6,8 +6,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "fn" argument must be one of type Function or null. ' + - 'Received type number' + message: 'The "fn" argument must be of type function or null. ' + + 'Received type number (42)' } ); diff --git a/test/parallel/test-process-hrtime.js b/test/parallel/test-process-hrtime.js index 81e50ccb7f85f0..8d469e1dccd3aa 100644 --- a/test/parallel/test-process-hrtime.js +++ b/test/parallel/test-process-hrtime.js @@ -38,7 +38,8 @@ 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 an instance of Array. Received type ' + + 'number (1)' }); common.expectsError(() => { process.hrtime([]); diff --git a/test/parallel/test-process-initgroups.js b/test/parallel/test-process-initgroups.js index 0cc0760d76aff0..6b4e3bdf1470b4 100644 --- a/test/parallel/test-process-initgroups.js +++ b/test/parallel/test-process-initgroups.js @@ -20,8 +20,8 @@ if (!common.isMainThread) name: 'TypeError', message: 'The "user" argument must be ' + - 'one of type number or string. ' + - `Received type ${typeof val}` + 'one of type number or string.' + + common.invalidArgTypeHelper(val) } ); }); @@ -36,8 +36,8 @@ if (!common.isMainThread) name: 'TypeError', message: 'The "extraGroup" argument must be ' + - 'one of type number or string. ' + - `Received type ${typeof val}` + 'one of type number or string.' + + common.invalidArgTypeHelper(val) } ); }); diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index 6d0af8bd3ef91a..a69961da6c94f6 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -42,8 +42,8 @@ const assert = require('assert'); assert.throws(() => process.kill(val), { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "pid" argument must be of type number. ' + - `Received type ${typeof val}` + message: 'The "pid" argument must be of type number.' + + common.invalidArgTypeHelper(val) }); }); diff --git a/test/parallel/test-process-setgroups.js b/test/parallel/test-process-setgroups.js index 31e56a2da32197..2e04c8a1756383 100644 --- a/test/parallel/test-process-setgroups.js +++ b/test/parallel/test-process-setgroups.js @@ -17,8 +17,8 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "groups" argument must be of type Array. ' + - 'Received type undefined' + message: 'The "groups" argument must be an instance of Array. ' + + 'Received undefined' } ); @@ -43,8 +43,8 @@ assert.throws( code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', message: 'The "groups[0]" argument must be ' + - 'one of type number or string. ' + - `Received type ${typeof val}` + 'one of type number or string.' + + common.invalidArgTypeHelper(val) } ); }); diff --git a/test/parallel/test-process-uid-gid.js b/test/parallel/test-process-uid-gid.js index dd11a2ec6e089d..6ca2e009571ef0 100644 --- a/test/parallel/test-process-uid-gid.js +++ b/test/parallel/test-process-uid-gid.js @@ -41,7 +41,7 @@ assert.throws(() => { }, { code: 'ERR_INVALID_ARG_TYPE', message: 'The "id" argument must be one of type ' + - 'number or string. Received type object' + 'number or string. Received an instance of Object' }); assert.throws(() => { diff --git a/test/parallel/test-require-resolve.js b/test/parallel/test-require-resolve.js index 484263c226f4a3..c89b4d89b861b5 100644 --- a/test/parallel/test-require-resolve.js +++ b/test/parallel/test-require-resolve.js @@ -38,20 +38,21 @@ assert.strictEqual(require.resolve('path'), 'path'); require(fixtures.path('require-resolve.js')); require(fixtures.path('resolve-paths', 'default', 'verify-paths.js')); -const re = /^The "request" argument must be of type string\. Received type \w+$/; [1, false, null, undefined, {}].forEach((value) => { + const message = 'The "request" argument must be of type string.' + + common.invalidArgTypeHelper(value); common.expectsError( () => { require.resolve(value); }, { code: 'ERR_INVALID_ARG_TYPE', - message: re + message }); common.expectsError( () => { require.resolve.paths(value); }, { code: 'ERR_INVALID_ARG_TYPE', - message: re + message }); }); diff --git a/test/parallel/test-string-decoder.js b/test/parallel/test-string-decoder.js index aaffa131cd8246..77c7736be900ce 100644 --- a/test/parallel/test-string-decoder.js +++ b/test/parallel/test-string-decoder.js @@ -196,8 +196,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "buf" argument must be one of type Buffer, TypedArray,' + - ' or DataView. Received type object' + message: 'The "buf" argument must be an instance of Buffer, TypedArray,' + + ' or DataView. Received null' } ); diff --git a/test/parallel/test-tls-basic-validations.js b/test/parallel/test-tls-basic-validations.js index 763b60fac536d8..f39d8553e7e075 100644 --- a/test/parallel/test-tls-basic-validations.js +++ b/test/parallel/test-tls-basic-validations.js @@ -13,7 +13,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.ciphers" property must be of type string.' + - ' Received type number' + ' Received type number (1)' }); common.expectsError( @@ -22,7 +22,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.ciphers" property must be of type string.' + - ' Received type number' + ' Received type number (1)' }); common.expectsError( @@ -54,8 +54,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.handshakeTimeout" property must ' + - 'be of type number. Received type string' + message: 'The "options.handshakeTimeout" property must be of type number.' + + " Received type string ('abcd')" } ); diff --git a/test/parallel/test-tls-clientcertengine-invalid-arg-type.js b/test/parallel/test-tls-clientcertengine-invalid-arg-type.js index b91e0f35c4c384..5b77141aaa5da4 100644 --- a/test/parallel/test-tls-clientcertengine-invalid-arg-type.js +++ b/test/parallel/test-tls-clientcertengine-invalid-arg-type.js @@ -10,5 +10,5 @@ const tls = require('tls'); common.expectsError( () => { tls.createSecureContext({ clientCertEngine: 0 }); }, { code: 'ERR_INVALID_ARG_TYPE', - message: / Received type number$/ }); + message: / Received type number \(0\)/ }); } diff --git a/test/parallel/test-tls-error-servername.js b/test/parallel/test-tls-error-servername.js index c42ff2fe73f466..034b2a57058eda 100644 --- a/test/parallel/test-tls-error-servername.js +++ b/test/parallel/test-tls-error-servername.js @@ -27,8 +27,8 @@ const client = connect({ client.setServername(value); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "name" argument must be of type string. ' + - `Received type ${typeof value}` + message: 'The "name" argument must be of type string.' + + common.invalidArgTypeHelper(value) }); }); diff --git a/test/parallel/test-tls-keyengine-invalid-arg-type.js b/test/parallel/test-tls-keyengine-invalid-arg-type.js index 385841a6541f94..d68b40cf0dbac3 100644 --- a/test/parallel/test-tls-keyengine-invalid-arg-type.js +++ b/test/parallel/test-tls-keyengine-invalid-arg-type.js @@ -12,7 +12,7 @@ common.expectsError( privateKeyIdentifier: 'key' }); }, { code: 'ERR_INVALID_ARG_TYPE', - message: / Received type number$/ }); + message: / Received type number \(0\)$/ }); common.expectsError( () => { @@ -20,4 +20,4 @@ common.expectsError( privateKeyIdentifier: 0 }); }, { code: 'ERR_INVALID_ARG_TYPE', - message: / Received type number$/ }); + message: / Received type number \(0\)$/ }); diff --git a/test/parallel/test-tls-no-cert-required.js b/test/parallel/test-tls-no-cert-required.js index ef1d366c919bb1..ed24863a2a3c22 100644 --- a/test/parallel/test-tls-no-cert-required.js +++ b/test/parallel/test-tls-no-cert-required.js @@ -39,13 +39,14 @@ tls.createServer(assert.fail) tls.createServer({}) .listen(0, common.mustCall(close)); -common.expectsError(() => tls.createServer('this is not valid'), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options" argument must be of type ' + - 'Object. Received type string' - } +common.expectsError( + () => tls.createServer('this is not valid'), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "options" argument must be of type object. ' + + "Received type string ('this is not valid')" + } ); tls.createServer() diff --git a/test/parallel/test-tls-options-boolean-check.js b/test/parallel/test-tls-options-boolean-check.js index 242df1140e41c2..4caf6215596587 100644 --- a/test/parallel/test-tls-options-boolean-check.js +++ b/test/parallel/test-tls-options-boolean-check.js @@ -74,20 +74,21 @@ const caArrDataView = toDataView(caCert); [true, certDataView], [true, false], [true, false], - [{ pem: keyBuff }, false, 'pem'], + [{ pem: keyBuff }, false], [[keyBuff, true], [certBuff, certBuff2], 1], [[true, keyStr2], [certStr, certStr2], 0], [[true, false], [certBuff, certBuff2], 0], [true, [certBuff, certBuff2]] ].forEach(([key, cert, index]) => { - const type = typeof (index === undefined ? key : key[index]); + const val = index === undefined ? key : key[index]; common.expectsError(() => { tls.createServer({ key, cert }); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.key" property must be one of type string, Buffer, ' + - `TypedArray, or DataView. Received type ${type}` + message: 'The "options.key" property must be of type string or an ' + + 'instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(val) }); }); @@ -98,21 +99,22 @@ const caArrDataView = toDataView(caCert); [keyDataView, true], [true, true], [false, true], - [false, { pem: keyBuff }, 'pem'], + [false, { pem: keyBuff }], [false, 1], [[keyBuff, keyBuff2], [true, certBuff2], 0], [[keyStr, keyStr2], [certStr, true], 1], [[keyStr, keyStr2], [true, false], 0], [[keyStr, keyStr2], true] ].forEach(([key, cert, index]) => { - const type = typeof (index === undefined ? cert : cert[index]); + const val = index === undefined ? cert : cert[index]; common.expectsError(() => { tls.createServer({ key, cert }); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.cert" property must be one of type string, Buffer,' + - ` TypedArray, or DataView. Received type ${type}` + message: 'The "options.cert" property must be of type string or an ' + + 'instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(val) }); }); @@ -139,14 +141,15 @@ const caArrDataView = toDataView(caCert); [keyBuff, certBuff, true], [keyBuff, certBuff, [caCert, true], 1] ].forEach(([key, cert, ca, index]) => { - const type = typeof (index === undefined ? ca : ca[index]); + const val = index === undefined ? ca : ca[index]; common.expectsError(() => { tls.createServer({ key, cert, ca }); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.ca" property must be one of type string, Buffer, ' + - `TypedArray, or DataView. Received type ${type}` + message: 'The "options.ca" property must be of type string or an instance' + + ' of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(val) }); }); diff --git a/test/parallel/test-url-format-invalid-input.js b/test/parallel/test-url-format-invalid-input.js index 1a0df32657ece8..5ba3b0bb4bf2ee 100644 --- a/test/parallel/test-url-format-invalid-input.js +++ b/test/parallel/test-url-format-invalid-input.js @@ -3,24 +3,24 @@ const common = require('../common'); const assert = require('assert'); const url = require('url'); -const throwsObjsAndReportTypes = new Map([ - [undefined, 'undefined'], - [null, 'object'], - [true, 'boolean'], - [false, 'boolean'], - [0, 'number'], - [function() {}, 'function'], - [Symbol('foo'), 'symbol'] -]); +const throwsObjsAndReportTypes = [ + undefined, + null, + true, + false, + 0, + function() {}, + Symbol('foo') +]; -for (const [urlObject, type] of throwsObjsAndReportTypes) { +for (const urlObject of throwsObjsAndReportTypes) { common.expectsError(function() { url.format(urlObject); }, { 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 one of type object or string.' + + common.invalidArgTypeHelper(urlObject) }); } assert.strictEqual(url.format(''), ''); diff --git a/test/parallel/test-url-format-whatwg.js b/test/parallel/test-url-format-whatwg.js index 95332e3f099899..ab3d18bdc3aa25 100644 --- a/test/parallel/test-url-format-whatwg.js +++ b/test/parallel/test-url-format-whatwg.js @@ -27,8 +27,8 @@ assert.strictEqual( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "options" argument must be of type Object. ' + - `Received type ${typeof value}` + message: 'The "options" argument must be of type object.' + + common.invalidArgTypeHelper(value) } ); }); diff --git a/test/parallel/test-url-parse-invalid-input.js b/test/parallel/test-url-parse-invalid-input.js index aad8462bfc2633..bfbd6636298b15 100644 --- a/test/parallel/test-url-parse-invalid-input.js +++ b/test/parallel/test-url-parse-invalid-input.js @@ -21,7 +21,8 @@ const url = require('url'); }, { 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.' + + common.invalidArgTypeHelper(val) }); }); diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js index 879177907451a8..7bb964b270ee2d 100644 --- a/test/parallel/test-util-callbackify.js +++ b/test/parallel/test-util-callbackify.js @@ -260,8 +260,8 @@ const values = [ }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "original" argument must be of type Function. ' + - `Received type ${typeof value}` + message: 'The "original" argument must be of type function.' + + common.invalidArgTypeHelper(value) }); }); } @@ -282,8 +282,8 @@ const values = [ }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The last argument must be of type Function. ' + - `Received type ${typeof value}` + message: 'The last argument must be of type function.' + + common.invalidArgTypeHelper(value) }); }); } diff --git a/test/parallel/test-util-deprecate-invalid-code.js b/test/parallel/test-util-deprecate-invalid-code.js index 635bab4252fb5b..29758556f19e75 100644 --- a/test/parallel/test-util-deprecate-invalid-code.js +++ b/test/parallel/test-util-deprecate-invalid-code.js @@ -7,7 +7,7 @@ const util = require('util'); common.expectsError(() => util.deprecate(() => {}, 'message', notString), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "code" argument must be of type string. ' + - `Received type ${typeof notString}` + message: 'The "code" argument must be of type string.' + + common.invalidArgTypeHelper(notString) }); }); diff --git a/test/parallel/test-util-inherits.js b/test/parallel/test-util-inherits.js index ed0800c33cec42..a190c8d8864a19 100644 --- a/test/parallel/test-util-inherits.js +++ b/test/parallel/test-util-inherits.js @@ -88,8 +88,8 @@ common.expectsError(function() { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "superCtor.prototype" property must be of type Object. ' + - 'Received type undefined' + message: 'The "superCtor.prototype" property must be of type object. ' + + 'Received undefined' }); common.expectsError(function() { @@ -97,8 +97,8 @@ common.expectsError(function() { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "superCtor" argument must be of type Function. ' + - 'Received type object' + message: 'The "superCtor" argument must be of type function. ' + + 'Received null' }); common.expectsError(function() { @@ -106,5 +106,5 @@ common.expectsError(function() { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "ctor" argument must be of type Function. Received type object' + 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 3b09e0c0fa20c2..93a22743cec320 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1456,8 +1456,8 @@ if (typeof Symbol !== 'undefined') { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type Object. ' + - 'Received type object' + message: 'The "options" argument must be of type object. ' + + 'Received null' } ); @@ -1466,8 +1466,8 @@ if (typeof Symbol !== 'undefined') { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type Object. ' + - 'Received type string' + message: 'The "options" argument must be of type object. ' + + "Received type string ('bad')" } ); } diff --git a/test/parallel/test-util-promisify.js b/test/parallel/test-util-promisify.js index 77601eae6daa9d..8b91deba3aa374 100644 --- a/test/parallel/test-util-promisify.js +++ b/test/parallel/test-util-promisify.js @@ -190,7 +190,7 @@ const stat = promisify(fs.stat); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "original" argument must be of type Function. ' + - `Received type ${typeof input}` + message: 'The "original" argument must be of type function.' + + common.invalidArgTypeHelper(input) }); }); diff --git a/test/parallel/test-uv-errno.js b/test/parallel/test-uv-errno.js index 768e2f27ddde75..4f97941f4b106a 100644 --- a/test/parallel/test-uv-errno.js +++ b/test/parallel/test-uv-errno.js @@ -31,8 +31,8 @@ function runTest(fn) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "err" argument must be of type number. ' + - `Received type ${typeof err}` + message: 'The "err" argument must be of type number.' + + common.invalidArgTypeHelper(err) }); }); diff --git a/test/parallel/test-v8-flag-type-check.js b/test/parallel/test-v8-flag-type-check.js index 1dcdee928b1ec3..51f485f543f784 100644 --- a/test/parallel/test-v8-flag-type-check.js +++ b/test/parallel/test-v8-flag-type-check.js @@ -8,8 +8,8 @@ const v8 = require('v8'); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "flags" argument must be of type string. ' + - `Received type ${typeof value}` + message: 'The "flags" argument must be of type string.' + + common.invalidArgTypeHelper(value) } ); }); diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js index 69fd859b028815..e530f671968cfa 100644 --- a/test/parallel/test-vm-basic.js +++ b/test/parallel/test-vm-basic.js @@ -102,8 +102,8 @@ const vm = require('vm'); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type Object. ' + - `Received type ${typeof input}` + message: 'The "options" argument must be of type object.' + + common.invalidArgTypeHelper(input) }); }); @@ -114,7 +114,7 @@ const vm = require('vm'); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: `The "options.${propertyName}" property must be of type string. ` + - 'Received type object' + 'Received null' }); }); @@ -125,7 +125,7 @@ const vm = require('vm'); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: `The "options.${propertyName}" property must be of type string. ` + - 'Received type object' + 'Received null' }); }); @@ -160,7 +160,7 @@ const vm = require('vm'); type: TypeError, code: 'ERR_INVALID_ARG_TYPE', message: 'The "code" argument must be of type string. ' + - 'Received type undefined' + 'Received undefined' }); vm.compileFunction(''); // Should pass without params or options @@ -168,8 +168,8 @@ const vm = require('vm'); common.expectsError(() => vm.compileFunction('', null), { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "params" argument must be of type Array. ' + - 'Received type object' + message: 'The "params" argument must be an instance of Array. ' + + 'Received null' }); // vm.compileFunction('', undefined, null); @@ -184,14 +184,14 @@ const vm = require('vm'); for (const option in optionTypes) { const typeErrorMessage = `The "options.${option}" property must be ` + - `${option === 'cachedData' ? 'one of' : 'of'} type`; + (option === 'cachedData' ? 'an instance of' : 'of type'); common.expectsError(() => { vm.compileFunction('', undefined, { [option]: null }); }, { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', message: typeErrorMessage + - ` ${optionTypes[option]}. Received type object` + ` ${optionTypes[option]}. Received null` }); } @@ -203,8 +203,8 @@ const vm = require('vm'); }, { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options.parsingContext" property must be of type ' + - `Context. Received type ${typeof value}` + message: 'The "options.parsingContext" property must be an instance ' + + `of Context.${common.invalidArgTypeHelper(value)}` }); } ); @@ -217,8 +217,8 @@ const vm = require('vm'); }, { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "params" argument must be of type Array. ' + - `Received type ${typeof value}` + message: 'The "params" argument must be an instance of Array.' + + common.invalidArgTypeHelper(value) }); } ); @@ -237,8 +237,8 @@ const vm = require('vm'); }, { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options.contextExtensions" property must be of type Array' + - '. Received type object' + message: 'The "options.contextExtensions" property must be an instance of' + + ' Array. Received null' }); common.expectsError(() => { @@ -247,7 +247,7 @@ const vm = require('vm'); type: TypeError, code: 'ERR_INVALID_ARG_TYPE', message: 'The "options.contextExtensions[0]" property must be of type ' + - 'object. Received type number' + 'object. Received type number (0)' }); const oldLimit = Error.stackTraceLimit; diff --git a/test/parallel/test-vm-cached-data.js b/test/parallel/test-vm-cached-data.js index 1b14999cdbc2f7..dbf369bf81c455 100644 --- a/test/parallel/test-vm-cached-data.js +++ b/test/parallel/test-vm-cached-data.js @@ -93,5 +93,5 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /must be one of type Buffer, TypedArray, or DataView/ + message: /must be an instance of Buffer, TypedArray, or DataView/ }); diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index e1cfd145f226ad..53326942d89df2 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -67,19 +67,22 @@ assert.strictEqual(gh1140Exception.toString(), 'Error'); const nonContextualSandboxError = { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /must be of type Object/ + message: /must be of type object/ }; const contextifiedSandboxError = { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /must be of type vm\.Context/ + message: /The "contextifiedSandbox" argument must be an vm\.Context/ }; [ [undefined, nonContextualSandboxError], - [null, nonContextualSandboxError], [0, nonContextualSandboxError], - [0.0, nonContextualSandboxError], ['', nonContextualSandboxError], - [{}, contextifiedSandboxError], [[], contextifiedSandboxError] + [null, nonContextualSandboxError], + [0, nonContextualSandboxError], + [0.0, nonContextualSandboxError], + ['', nonContextualSandboxError], + [{}, contextifiedSandboxError], + [[], contextifiedSandboxError] ].forEach((e) => { common.expectsError(() => { script.runInContext(e[0]); }, e[1]); common.expectsError(() => { vm.runInContext('', e[0]); }, e[1]); diff --git a/test/parallel/test-vm-module-errors.js b/test/parallel/test-vm-module-errors.js index e5a766e37dfdb8..a76666c02835d0 100644 --- a/test/parallel/test-vm-module-errors.js +++ b/test/parallel/test-vm-module-errors.js @@ -80,8 +80,8 @@ async function checkModuleState() { await m.evaluate(false); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options" argument must be of type Object. ' + - 'Received type boolean' + message: 'The "options" argument must be of type object. ' + + 'Received type boolean (false)' }); common.expectsError(() => { @@ -163,8 +163,8 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.importModuleDynamically"' + - ' property must be of type function. Received type string' + message: 'The "options.importModuleDynamically" property must be of type ' + + "function. Received type string ('hucairz')" }); // Check the JavaScript engine deals with exceptions correctly @@ -204,7 +204,7 @@ async function checkInvalidOptionForEvaluate() { name: 'TypeError', message: 'The "options.breakOnSigint" property must be of type boolean. ' + - 'Received type string', + "Received type string ('a-string')", code: 'ERR_INVALID_ARG_TYPE' }); } diff --git a/test/parallel/test-worker-process-env.js b/test/parallel/test-worker-process-env.js index 45eaef6fc38eba..1316afd7835574 100644 --- a/test/parallel/test-worker-process-env.js +++ b/test/parallel/test-worker-process-env.js @@ -28,8 +28,9 @@ if (!workerData && process.argv[2] !== 'child') { }, { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options.env" property must be one of type object, ' + - 'undefined, null, or worker_threads.SHARE_ENV. Received type number' + message: 'The "options.env" property must be of type object or ' + + 'one of undefined, null, or worker_threads.SHARE_ENV. Received type ' + + 'number (42)' }); } else if (workerData === 'runInWorker') { // Env vars from the parent thread are inherited. diff --git a/test/parallel/test-worker-type-check.js b/test/parallel/test-worker-type-check.js index 96475560354897..2d180130390ee8 100644 --- a/test/parallel/test-worker-type-check.js +++ b/test/parallel/test-worker-type-check.js @@ -19,8 +19,8 @@ const { Worker } = require('worker_threads'); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "filename" argument must be of type string. ' + - `Received type ${typeof val}` + message: 'The "filename" argument must be of type string.' + + common.invalidArgTypeHelper(val) } ); }); diff --git a/test/parallel/test-zlib-convenience-methods.js b/test/parallel/test-zlib-convenience-methods.js index b60d0e15ac263a..65c842b66a86c9 100644 --- a/test/parallel/test-zlib-convenience-methods.js +++ b/test/parallel/test-zlib-convenience-methods.js @@ -128,6 +128,6 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "callback" argument must be of type function. ' + - 'Received type undefined' + 'Received undefined' } ); diff --git a/test/parallel/test-zlib-deflate-constructors.js b/test/parallel/test-zlib-deflate-constructors.js index 5d5e9fb4a2edd1..3cb4eca5ea2af2 100644 --- a/test/parallel/test-zlib-deflate-constructors.js +++ b/test/parallel/test-zlib-deflate-constructors.js @@ -19,7 +19,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.chunkSize" property must be of type number. ' + - 'Received type string' + "Received type string ('test')" } ); @@ -53,7 +53,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.windowBits" property must be of type number. ' + - 'Received type string' + "Received type string ('test')" } ); @@ -94,7 +94,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.level" property must be of type number. ' + - 'Received type string' + "Received type string ('test')" } ); @@ -135,7 +135,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "level" argument must be of type number. ' + - 'Received type string' + "Received type string ('test')" } ); @@ -176,7 +176,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.memLevel" property must be of type number. ' + - 'Received type string' + "Received type string ('test')" } ); @@ -224,7 +224,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.strategy" property must be of type number. ' + - 'Received type string' + "Received type string ('test')" } ); @@ -265,7 +265,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "strategy" argument must be of type number. ' + - 'Received type string' + "Received type string ('test')" } ); @@ -305,7 +305,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options.dictionary" property must be one of type Buffer, ' + - 'TypedArray, DataView, or ArrayBuffer. Received type string' + message: 'The "options.dictionary" property must be an instance of Buffer' + + ', TypedArray, DataView, or ArrayBuffer. Received type string ' + + "('not a buffer')" } ); diff --git a/test/parallel/test-zlib-flush-flags.js b/test/parallel/test-zlib-flush-flags.js index 67c58b95d3105e..64390a3137d994 100644 --- a/test/parallel/test-zlib-flush-flags.js +++ b/test/parallel/test-zlib-flush-flags.js @@ -10,7 +10,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.flush" property must be of type number. ' + - 'Received type string' + "Received type string ('foobar')" } ); @@ -32,7 +32,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "options.finishFlush" property must be of type number. ' + - 'Received type string' + "Received type string ('foobar')" } ); diff --git a/test/parallel/test-zlib-not-string-or-buffer.js b/test/parallel/test-zlib-not-string-or-buffer.js index bf59e86d5c3664..6a3b2b772f3788 100644 --- a/test/parallel/test-zlib-not-string-or-buffer.js +++ b/test/parallel/test-zlib-not-string-or-buffer.js @@ -21,9 +21,9 @@ const zlib = require('zlib'); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "buffer" argument must be one of type string, Buffer, ' + - 'TypedArray, DataView, or ArrayBuffer. ' + - `Received type ${typeof input}` + message: 'The "buffer" argument must be of type string or an instance ' + + 'of Buffer, TypedArray, DataView, or ArrayBuffer.' + + common.invalidArgTypeHelper(input) } ); }); diff --git a/test/sequential/test-crypto-timing-safe-equal.js b/test/sequential/test-crypto-timing-safe-equal.js index 75385e5f88ad50..05d5a2a3881900 100644 --- a/test/sequential/test-crypto-timing-safe-equal.js +++ b/test/sequential/test-crypto-timing-safe-equal.js @@ -47,8 +47,8 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "buf1" argument must be one of type Buffer, TypedArray, or ' + - 'DataView. Received type string' + 'The "buf1" argument must be an instance of Buffer, TypedArray, or ' + + "DataView. Received type string ('not a buffer')" } ); @@ -58,7 +58,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "buf2" argument must be one of type Buffer, TypedArray, or ' + - 'DataView. Received type string' + 'The "buf2" argument must be an instance of Buffer, TypedArray, or ' + + "DataView. Received type string ('not a buffer')" } ); diff --git a/test/sequential/test-heapdump.js b/test/sequential/test-heapdump.js index a65b33c3138a62..474979914a209e 100644 --- a/test/sequential/test-heapdump.js +++ b/test/sequential/test-heapdump.js @@ -28,8 +28,9 @@ process.chdir(tmpdir.path); common.expectsError(() => writeHeapSnapshot(i), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "path" argument must be one of type string, Buffer, or URL.' + - ` Received type ${typeof i}` + message: 'The "path" argument must be of type string or an instance of ' + + 'Buffer or URL.' + + common.invalidArgTypeHelper(i) }); }); diff --git a/test/sequential/test-inspector-module.js b/test/sequential/test-inspector-module.js index 010f03c6e43e83..166b726db4b88d 100644 --- a/test/sequential/test-inspector-module.js +++ b/test/sequential/test-inspector-module.js @@ -28,8 +28,8 @@ session.post('Runtime.evaluate', { expression: '2 + 2' }); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "method" argument must be of type string. ' + - `Received type ${typeof i}` + 'The "method" argument must be of type string.' + + common.invalidArgTypeHelper(i) } ); }); @@ -41,8 +41,8 @@ session.post('Runtime.evaluate', { expression: '2 + 2' }); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "params" argument must be of type Object. ' + - `Received type ${typeof i}` + 'The "params" argument must be of type object.' + + common.invalidArgTypeHelper(i) } ); });