From c6e586bad425464044911bde7352fec041a3fd00 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 23 Sep 2019 08:14:35 +0200 Subject: [PATCH 1/4] buffer: improve .from() error details This makes sure the original input is passed to the error in case no matching inputs are found. Instead of passing along all values, only valid or possibliy valid values are passed through. That way invalid values end up in the error case with the original input. --- lib/buffer.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 74d6511b35f5..2bed199f5744 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -291,17 +291,21 @@ Buffer.from = function from(value, encodingOrOffset, length) { return fromArrayBuffer(value, encodingOrOffset, length); const valueOf = value.valueOf && value.valueOf(); - if (valueOf !== null && valueOf !== undefined && valueOf !== value) - return Buffer.from(valueOf, encodingOrOffset, length); + if (valueOf != null && + valueOf !== value && + (typeof valueOf === 'string' || typeof valueOf === 'object')) { + return from(valueOf, encodingOrOffset, length); + } const b = fromObject(value); if (b) return b; if (typeof value[SymbolToPrimitive] === 'function') { - return Buffer.from(value[SymbolToPrimitive]('string'), - encodingOrOffset, - length); + const primitive = value[SymbolToPrimitive]('string'); + if (typeof primitive === 'string') { + return fromString(primitive, encodingOrOffset); + } } } From 14309b2b01ca47a3496a54cb1dd8d997d9e94154 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 23 Sep 2019 08:17:25 +0200 Subject: [PATCH 2/4] 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. --- lib/_http_server.js | 2 +- lib/child_process.js | 4 +- lib/internal/child_process.js | 2 +- lib/internal/console/constructor.js | 2 +- lib/internal/crypto/keygen.js | 4 +- lib/internal/crypto/keys.js | 4 +- lib/internal/errors.js | 138 +++++++++++++----- lib/internal/fs/utils.js | 2 +- lib/internal/http2/core.js | 2 +- lib/internal/process/per_thread.js | 2 +- lib/internal/streams/end-of-stream.js | 2 +- lib/internal/worker.js | 2 +- lib/trace_events.js | 2 +- lib/vm.js | 2 +- test/common/index.js | 20 +++ 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 | 21 +-- 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 | 4 +- test/parallel/test-console-instance.js | 4 +- 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-rmdir-recursive.js | 2 +- 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/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 | 14 +- 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/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 | 34 ++--- 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 +- 138 files changed, 655 insertions(+), 544 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index b31762b4c1ed..8c0b77137f39 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -323,7 +323,7 @@ function Server(options, requestListener) { } else if (options == null || typeof options === 'object') { options = { ...options }; } else { - throw new ERR_INVALID_ARG_TYPE('options', 'object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); } this[kIncomingMessage] = options.IncomingMessage || IncomingMessage; diff --git a/lib/child_process.js b/lib/child_process.js index 0549e5daf7d1..6d62329c7fe0 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -412,7 +412,7 @@ function normalizeSpawnArguments(file, args, options) { } else if (args == null) { args = []; } else if (typeof args !== 'object') { - throw new ERR_INVALID_ARG_TYPE('args', 'object', args); + throw new ERR_INVALID_ARG_TYPE('args', 'Object', args); } else { options = args; args = []; @@ -421,7 +421,7 @@ function normalizeSpawnArguments(file, args, options) { if (options === undefined) options = {}; else if (options === null || typeof options !== 'object') - throw new ERR_INVALID_ARG_TYPE('options', 'object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); // Validate the cwd, if present. if (options.cwd != null && diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index b07a38d6f6f5..a4236e565398 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -707,7 +707,7 @@ function setupChannel(target, channel, serializationMode) { typeof message !== 'number' && typeof message !== 'boolean') { throw new ERR_INVALID_ARG_TYPE( - 'message', ['string', 'object', 'number', 'boolean'], message); + 'message', ['string', 'Object', 'number', 'boolean'], message); } // Support legacy function signature diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index aff24f93455c..62c1e8c262e7 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -111,7 +111,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) { } optionsMap.set(this, inspectOptions); } else if (inspectOptions !== undefined) { - throw new ERR_INVALID_ARG_TYPE('inspectOptions', 'object', inspectOptions); + throw new ERR_INVALID_ARG_TYPE('inspectOptions', 'Object', inspectOptions); } // Bind the prototype functions to this Console instance diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index 88d2822fa6fa..ce0940d3eec6 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -134,11 +134,11 @@ function check(type, options, callback) { let cipher, passphrase, publicType, publicFormat, privateType, privateFormat; if (options !== undefined && typeof options !== 'object') - throw new ERR_INVALID_ARG_TYPE('options', 'object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); function needOptions() { if (options == null) - throw new ERR_INVALID_ARG_TYPE('options', 'object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); return options; } diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 087cef014f0f..7fa336d780f5 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -47,7 +47,7 @@ class KeyObject { if (type !== 'secret' && type !== 'public' && type !== 'private') throw new ERR_INVALID_ARG_VALUE('type', type); if (typeof handle !== 'object') - throw new ERR_INVALID_ARG_TYPE('handle', 'object', handle); + throw new ERR_INVALID_ARG_TYPE('handle', 'Object', handle); this[kKeyType] = type; @@ -178,7 +178,7 @@ function isStringOrBuffer(val) { function parseKeyEncoding(enc, keyType, isPublic, objName) { if (enc === null || typeof enc !== 'object') - throw new ERR_INVALID_ARG_TYPE('options', 'object', enc); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', enc); const isInput = keyType === undefined; diff --git a/lib/internal/errors.js b/lib/internal/errors.js index ad12d99c7cc4..564ea5709d95 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -23,6 +23,11 @@ const { const messages = new Map(); const codes = {}; +const classRegExp = /^([A-Z][a-z0-9]*)+$/; +const kTypes = [ + 'string', 'boolean', 'number', 'symbol', 'bigint', 'function' +]; + const { kMaxLength } = internalBinding('buffer'); const MainContextError = Error; @@ -610,26 +615,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 +911,106 @@ 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); + } else if (value === 'Function') { // 'Function' should be handled as type + types.push('function'); + } else if (classRegExp.test(value)) { + instances.push(value); + } else { + assert(value !== 'object', + 'The value "object" should be written as "Object"'); + other.push(value); + } + } + + 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 '; } - // TODO(BridgeAR): Improve the output by showing `null` and similar. - msg += `. Received type ${typeof actual}`; + 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 +1098,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/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index f75e71a914c2..76a652f35f10 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -580,7 +580,7 @@ const validateRmdirOptions = hideStackFrames((options) => { if (options === undefined) return defaultRmdirOptions; if (options === null || typeof options !== 'object') - throw new ERR_INVALID_ARG_TYPE('options', 'object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); options = { ...defaultRmdirOptions, ...options }; diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 0bbf74cdc71d..ea05feb3e798 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1505,7 +1505,7 @@ class ServerHttp2Session extends Http2Session { // be invalid. if (typeof origin !== 'string') { throw new ERR_INVALID_ARG_TYPE('originOrStream', - ['string', 'number', 'URL', 'object'], + ['string', 'number', 'URL', 'Object'], originOrStream); } else if (origin === 'null' || origin.length === 0) { throw new ERR_HTTP2_ALTSVC_INVALID_ORIGIN(); diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 2ead72781d53..300c61a2b02e 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -58,7 +58,7 @@ function wrapProcessMethods(binding) { if (prevValue) { if (!previousValueIsValid(prevValue.user)) { if (typeof prevValue !== 'object') - throw new ERR_INVALID_ARG_TYPE('prevValue', 'object', prevValue); + throw new ERR_INVALID_ARG_TYPE('prevValue', 'Object', prevValue); if (typeof prevValue.user !== 'number') { throw new ERR_INVALID_ARG_TYPE('prevValue.user', diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index bb01e800becd..531edeabdb6e 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -20,7 +20,7 @@ function eos(stream, opts, callback) { } else if (opts == null) { opts = {}; } else if (typeof opts !== 'object') { - throw new ERR_INVALID_ARG_TYPE('opts', 'object', opts); + throw new ERR_INVALID_ARG_TYPE('opts', 'Object', opts); } if (typeof callback !== 'function') { throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback); diff --git a/lib/internal/worker.js b/lib/internal/worker.js index f078d5329d60..340a93d602c1 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -118,7 +118,7 @@ class Worker extends EventEmitter { } else if (options.env !== SHARE_ENV) { throw new ERR_INVALID_ARG_TYPE( 'options.env', - ['object', 'undefined', 'null', 'worker_threads.SHARE_ENV'], + ['Object', 'undefined', 'null', 'worker_threads.SHARE_ENV'], options.env); } diff --git a/lib/trace_events.js b/lib/trace_events.js index 1ff2b5a4fb15..57f0ab32a664 100644 --- a/lib/trace_events.js +++ b/lib/trace_events.js @@ -79,7 +79,7 @@ class Tracing { function createTracing(options) { if (typeof options !== 'object' || options === null) - throw new ERR_INVALID_ARG_TYPE('options', 'object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); if (!ArrayIsArray(options.categories)) { throw new ERR_INVALID_ARG_TYPE('options.categories', 'string[]', diff --git a/lib/vm.js b/lib/vm.js index a4b5b37e83cf..03ff0fcd03ac 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -371,7 +371,7 @@ function compileFunction(code, params, options = {}) { if (typeof extension !== 'object') { throw new ERR_INVALID_ARG_TYPE( `options.contextExtensions[${i}]`, - 'object', + 'Object', extension ); } diff --git a/test/common/index.js b/test/common/index.js index d774bffe0fad..544ad7865692 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -717,6 +717,25 @@ 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, @@ -735,6 +754,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 5493c6c47c96..1a9e6dea826c 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 6291e0365c2f..b9e7fa42302c 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 cbb4431f1952..dd98c0a23339 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 3db63a816a52..3b85291835cc 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 an instance of Object.' + + common.invalidArgTypeHelper(input) }); }); } @@ -937,8 +937,8 @@ 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' + + " Object, Error, or RegExp. Received type string ('Error message')" } ); @@ -951,8 +951,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 Object, Error, or RegExp.' + + common.invalidArgTypeHelper(input) } ); }); @@ -1030,8 +1031,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 de3e7fa52390..75bcb03d1913 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 699d13e9552a..bb22b8799325 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 c0c7228d0d0b..369e8cb19161 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 3769e4d41ac2..df3b429a03c4 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 e2bd1380d2ce..b790e461bcfa 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 6be3a39fa00a..2e7541fb58b0 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 91c79a5be8b1..055fe56de26f 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 26243d7f199f..aa5c701b543c 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 ec798381696e..165b38893f9e 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 794822f13ac8..8e5ec8e926cb 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 3059e13780e5..4eb42ca5bff8 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 31b29dee5b08..45806359ad6c 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 9c9ed2d0e849..20e1709b07bd 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 an instance of 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 44d22ab2115e..aab2b236f6eb 100644 --- a/test/parallel/test-child-process-fork.js +++ b/test/parallel/test-child-process-fork.js @@ -51,8 +51,8 @@ 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', + message: 'The "message" argument must be one of type string, number, or ' + + 'boolean or an instance of Object. 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 1c8b54ef4ca7..42ce6c27d342 100644 --- a/test/parallel/test-console-instance.js +++ b/test/parallel/test-console-instance.js @@ -140,8 +140,8 @@ out.write = err.write = (d) => {}; }); }, { - message: 'The "inspectOptions" argument must be of type object.' + - ` Received type ${typeof inspectOptions}`, + message: 'The "inspectOptions" argument must be an instance of Object.' + + 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 e987be212958..8d3219059d03 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 ce6ea4e3b81e..45e4bd6ea72f 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 d9cc725da1d3..d4eda6bb1fca 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 bf991a5c34ea..027b58b8262b 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 ca76672de8dc..e3ac270fef1a 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 a0c3ffeb20ca..0ccc300aa257 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 2601994ab1a4..dd7b5631042d 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 dc995be041ed..3f47d1592f07 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 an instance of 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 an instance of Object/ }); } diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index 8c3432e06cb6..6134bf71765c 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 an instance of 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 an instance of Object. ' + + 'Received type number (0)' }); } diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js index 86df47f2f663..a6aeefad0d43 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 1d40c8b1814d..4650b3c8bd35 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 a16d25f540e1..d98317a35470 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 ae6232836446..b6dc52bd0b7f 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 2e3aad63fe30..805b7e344b77 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 7f4bcf53eb5b..d64558bac442 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 f8f2a2de1368..644ffb3327ba 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 6eea4894b1c1..967a22383fab 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 c6e8cb3c6692..36af63de1013 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 bdf52a32e0fa..9f09ee4ebf65 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 e854574a2eab..d9143f52d33e 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 7812de670ff5..d7ebf424380c 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 1bdf0cbf126a..5b74185b12c4 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 c5cf009259d7..21f381af85fa 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 8b9d6215601e..97ae403ddd25 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 1e898d389133..bad5adea448f 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 cc8caf86fd3c..8314c6f73daa 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 6168d5c20ab8..52930a203edd 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 ebbc2792e137..a6d5c0c95dac 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 4872e550dba3..cf28d54e9d96 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 28a513d10f2d..70027e33ed9e 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 2cd42f65669e..5e9a2bd75ea2 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 3c7903c98f04..a5ced6970597 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 f5ac78a23026..dbe036794ceb 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 e6fe6231ffd9..03ddf7f36d1f 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 3b245058ff6f..4f0aaf888db7 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 bc1277740fd5..09004dcb623b 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-rmdir-recursive.js b/test/parallel/test-fs-rmdir-recursive.js index 628bba5d6fc4..a5d6eef1515e 100644 --- a/test/parallel/test-fs-rmdir-recursive.js +++ b/test/parallel/test-fs-rmdir-recursive.js @@ -182,7 +182,7 @@ function removeAsync(dir) { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /^The "options" argument must be of type object\./ + message: /^The "options" argument must be an instance of Object\./ }); }); diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index bde3e06765cb..32acf65b7b96 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 c52ffbc105ff..d1784fdd3a07 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 044ff622bdb1..c41f31376f2a 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 fb674bbfeab4..ea24f406cc06 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 828d7fa79a50..5a5ec2fb95f1 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 27cb77951cf5..664fb4931022 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 72440391fa29..6ec6b7d6271a 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 0ff05f234c2c..b4e4018e1d0b 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 0070f5399470..0f428b9546bd 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 203b552ef7f7..d13d685b3e50 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 8b38ab147f3d..06f37c8a47ce 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 c47de48b6a2c..82b81a3d3fbb 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 fe722c84ee78..ca148ff00700 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-getpackedsettings.js b/test/parallel/test-http2-getpackedsettings.js index 341cfb4fc799..8eca10cf49f4 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 d7c451569e27..b94a670a1a3c 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 14dc4a536617..00a89c65b0eb 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 an instance of 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 993867bb21c6..27bfd19c6f08 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 5de21e7855ea..06e5f6161dbd 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 9dde6660ea25..0109a147aaa8 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 323e6bdd24e4..be41f2020250 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 136c76cc049c..d9bd588f63be 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 an instance of 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 295082e1cee1..65a17f9f7605 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 0b44c7795e5b..ec28d37bf7e0 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 614da43aba0a..6f985faccd92 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 40b6de72a329..24a2a8cc9fad 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 19b037ee0fc9..cd502202baaf 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 901bdb0b93de..d0578d560220 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 an instance of Object.' + + common.invalidArgTypeHelper(pathObject) }); }); } diff --git a/test/parallel/test-performance-function.js b/test/parallel/test-performance-function.js index 25e3db639030..5271f419a3e3 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 75097cb8c771..a37f0dc45e0d 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 an instance of Object.' + + common.invalidArgTypeHelper(input) }); }); diff --git a/test/parallel/test-process-cpuUsage.js b/test/parallel/test-process-cpuUsage.js index 76e0702b9e4d..ed5f806ab06d 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(); @@ -38,8 +38,8 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "prevValue" argument must be of type object. ' + - 'Received type number' + message: 'The "prevValue" argument must be an instance of Object. ' + + '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 b9e0630dab5e..33d630b34dd0 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 d2f5b8617725..5f89852b6e18 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 81e50ccb7f85..8d469e1dccd3 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 0cc0760d76af..6b4e3bdf1470 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 6d0af8bd3ef9..a69961da6c94 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 31e56a2da321..2e04c8a17563 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 dd11a2ec6e08..6ca2e009571e 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 484263c226f4..c89b4d89b861 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 aaffa131cd82..77c7736be900 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 763b60fac536..f39d8553e7e0 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 b91e0f35c4c3..5b77141aaa5d 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 c42ff2fe73f4..034b2a57058e 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-no-cert-required.js b/test/parallel/test-tls-no-cert-required.js index ef1d366c919b..e969e6d54c06 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 an instance of 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 242df1140e41..4caf62155965 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 1a0df32657ec..4bc22bd43352 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 of type string or an instance ' + + `of Object.${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 95332e3f0998..827266079a73 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 an instance of 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 aad8462bfc26..bfbd6636298b 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 879177907451..7bb964b270ee 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 635bab4252fb..29758556f19e 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 ed0800c33cec..cae54b612b31 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 an ' + + 'instance of 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 3b09e0c0fa20..c43daccefffd 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 an instance of 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 an instance of Object. ' + + "Received type string ('bad')" } ); } diff --git a/test/parallel/test-util-promisify.js b/test/parallel/test-util-promisify.js index 77601eae6daa..8b91deba3aa3 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 768e2f27ddde..4f97941f4b10 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 1dcdee928b1e..51f485f543f7 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 69fd859b0288..38f345b63238 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 an instance of 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(() => { @@ -246,8 +246,8 @@ 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' + message: 'The "options.contextExtensions[0]" property must be an instance' + + ' of 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 1b14999cdbc2..dbf369bf81c4 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 e1cfd145f226..9118b8155ba6 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 an instance of 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 e5a766e37dfd..aaea483316f9 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 an instance of 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 45eaef6fc38e..0a366289e880 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 an instance of 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 964755603548..2d180130390e 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 b60d0e15ac26..65c842b66a86 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 5d5e9fb4a2ed..3cb4eca5ea2a 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 67c58b95d310..64390a3137d9 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 bf59e86d5c36..6a3b2b772f37 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 75385e5f88ad..05d5a2a38819 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 a65b33c3138a..474979914a20 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 010f03c6e43e..2d887518b891 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 an instance of Object.' + + common.invalidArgTypeHelper(i) } ); }); From b03332403e04aff9a133fb1883615c304049205c Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 26 Sep 2019 18:10:01 +0200 Subject: [PATCH 3/4] fixup: use `object` instead of `Object` is most cases --- lib/_http_server.js | 2 +- lib/child_process.js | 4 +-- lib/internal/child_process.js | 2 +- lib/internal/console/constructor.js | 2 +- lib/internal/crypto/keygen.js | 4 +-- lib/internal/crypto/keys.js | 4 +-- lib/internal/errors.js | 26 ++++++++++++++++--- lib/internal/fs/utils.js | 2 +- lib/internal/http2/core.js | 2 +- lib/internal/process/per_thread.js | 2 +- lib/internal/streams/end-of-stream.js | 2 +- lib/internal/worker.js | 2 +- lib/trace_events.js | 2 +- lib/vm.js | 2 +- test/parallel/test-assert.js | 11 ++++---- .../test-child-process-constructor.js | 2 +- test/parallel/test-child-process-fork.js | 4 +-- test/parallel/test-console-instance.js | 2 +- test/parallel/test-crypto-key-objects.js | 4 +-- test/parallel/test-crypto-keygen.js | 4 +-- test/parallel/test-fs-rmdir-recursive.js | 2 +- .../test-http2-createsecureserver-options.js | 8 +++--- .../test-http2-createserver-options.js | 8 +++--- test/parallel/test-http2-misc-util.js | 2 +- test/parallel/test-http2-util-asserts.js | 2 +- test/parallel/test-path-parse-format.js | 2 +- test/parallel/test-performanceobserver.js | 2 +- test/parallel/test-process-cpuUsage.js | 2 +- .../test-tls-keyengine-invalid-arg-type.js | 4 +-- test/parallel/test-tls-no-cert-required.js | 2 +- .../parallel/test-url-format-invalid-input.js | 4 +-- test/parallel/test-url-format-whatwg.js | 2 +- test/parallel/test-util-inherits.js | 4 +-- test/parallel/test-util-inspect.js | 4 +-- test/parallel/test-vm-basic.js | 6 ++--- test/parallel/test-vm-context.js | 2 +- test/parallel/test-vm-module-errors.js | 2 +- test/parallel/test-worker-process-env.js | 2 +- test/sequential/test-inspector-module.js | 2 +- 39 files changed, 83 insertions(+), 64 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index 8c0b77137f39..b31762b4c1ed 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -323,7 +323,7 @@ function Server(options, requestListener) { } else if (options == null || typeof options === 'object') { options = { ...options }; } else { - throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'object', options); } this[kIncomingMessage] = options.IncomingMessage || IncomingMessage; diff --git a/lib/child_process.js b/lib/child_process.js index 6d62329c7fe0..0549e5daf7d1 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -412,7 +412,7 @@ function normalizeSpawnArguments(file, args, options) { } else if (args == null) { args = []; } else if (typeof args !== 'object') { - throw new ERR_INVALID_ARG_TYPE('args', 'Object', args); + throw new ERR_INVALID_ARG_TYPE('args', 'object', args); } else { options = args; args = []; @@ -421,7 +421,7 @@ function normalizeSpawnArguments(file, args, options) { if (options === undefined) options = {}; else if (options === null || typeof options !== 'object') - throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'object', options); // Validate the cwd, if present. if (options.cwd != null && diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index a4236e565398..b07a38d6f6f5 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -707,7 +707,7 @@ function setupChannel(target, channel, serializationMode) { typeof message !== 'number' && typeof message !== 'boolean') { throw new ERR_INVALID_ARG_TYPE( - 'message', ['string', 'Object', 'number', 'boolean'], message); + 'message', ['string', 'object', 'number', 'boolean'], message); } // Support legacy function signature diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 62c1e8c262e7..aff24f93455c 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -111,7 +111,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) { } optionsMap.set(this, inspectOptions); } else if (inspectOptions !== undefined) { - throw new ERR_INVALID_ARG_TYPE('inspectOptions', 'Object', inspectOptions); + throw new ERR_INVALID_ARG_TYPE('inspectOptions', 'object', inspectOptions); } // Bind the prototype functions to this Console instance diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index ce0940d3eec6..88d2822fa6fa 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -134,11 +134,11 @@ function check(type, options, callback) { let cipher, passphrase, publicType, publicFormat, privateType, privateFormat; if (options !== undefined && typeof options !== 'object') - throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'object', options); function needOptions() { if (options == null) - throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'object', options); return options; } diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 7fa336d780f5..087cef014f0f 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -47,7 +47,7 @@ class KeyObject { if (type !== 'secret' && type !== 'public' && type !== 'private') throw new ERR_INVALID_ARG_VALUE('type', type); if (typeof handle !== 'object') - throw new ERR_INVALID_ARG_TYPE('handle', 'Object', handle); + throw new ERR_INVALID_ARG_TYPE('handle', 'object', handle); this[kKeyType] = type; @@ -178,7 +178,7 @@ function isStringOrBuffer(val) { function parseKeyEncoding(enc, keyType, isPublic, objName) { if (enc === null || typeof enc !== 'object') - throw new ERR_INVALID_ARG_TYPE('options', 'Object', enc); + throw new ERR_INVALID_ARG_TYPE('options', 'object', enc); const isInput = keyType === undefined; diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 564ea5709d95..8b0a7a0d7aab 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -24,8 +24,18 @@ 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', 'boolean', 'number', 'symbol', 'bigint', 'function' + 'string', + 'function', + 'number', + 'object', + // Accept 'Function' and 'Object' as alternative to the lower cased version. + 'Function', + 'Object', + 'boolean', + 'bigint', + 'symbol' ]; const { kMaxLength } = internalBinding('buffer'); @@ -940,9 +950,7 @@ E('ERR_INVALID_ARG_TYPE', assert(typeof value === 'string', 'All expected entries have to be of type string'); if (kTypes.includes(value)) { - types.push(value); - } else if (value === 'Function') { // 'Function' should be handled as type - types.push('function'); + types.push(value.toLowerCase()); } else if (classRegExp.test(value)) { instances.push(value); } else { @@ -952,6 +960,16 @@ E('ERR_INVALID_ARG_TYPE', } } + // 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(); diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 76a652f35f10..f75e71a914c2 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -580,7 +580,7 @@ const validateRmdirOptions = hideStackFrames((options) => { if (options === undefined) return defaultRmdirOptions; if (options === null || typeof options !== 'object') - throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'object', options); options = { ...defaultRmdirOptions, ...options }; diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index ea05feb3e798..0bbf74cdc71d 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1505,7 +1505,7 @@ class ServerHttp2Session extends Http2Session { // be invalid. if (typeof origin !== 'string') { throw new ERR_INVALID_ARG_TYPE('originOrStream', - ['string', 'number', 'URL', 'Object'], + ['string', 'number', 'URL', 'object'], originOrStream); } else if (origin === 'null' || origin.length === 0) { throw new ERR_HTTP2_ALTSVC_INVALID_ORIGIN(); diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 300c61a2b02e..2ead72781d53 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -58,7 +58,7 @@ function wrapProcessMethods(binding) { if (prevValue) { if (!previousValueIsValid(prevValue.user)) { if (typeof prevValue !== 'object') - throw new ERR_INVALID_ARG_TYPE('prevValue', 'Object', prevValue); + throw new ERR_INVALID_ARG_TYPE('prevValue', 'object', prevValue); if (typeof prevValue.user !== 'number') { throw new ERR_INVALID_ARG_TYPE('prevValue.user', diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index 531edeabdb6e..bb01e800becd 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -20,7 +20,7 @@ function eos(stream, opts, callback) { } else if (opts == null) { opts = {}; } else if (typeof opts !== 'object') { - throw new ERR_INVALID_ARG_TYPE('opts', 'Object', opts); + throw new ERR_INVALID_ARG_TYPE('opts', 'object', opts); } if (typeof callback !== 'function') { throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback); diff --git a/lib/internal/worker.js b/lib/internal/worker.js index 340a93d602c1..f078d5329d60 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -118,7 +118,7 @@ class Worker extends EventEmitter { } else if (options.env !== SHARE_ENV) { throw new ERR_INVALID_ARG_TYPE( 'options.env', - ['Object', 'undefined', 'null', 'worker_threads.SHARE_ENV'], + ['object', 'undefined', 'null', 'worker_threads.SHARE_ENV'], options.env); } diff --git a/lib/trace_events.js b/lib/trace_events.js index 57f0ab32a664..1ff2b5a4fb15 100644 --- a/lib/trace_events.js +++ b/lib/trace_events.js @@ -79,7 +79,7 @@ class Tracing { function createTracing(options) { if (typeof options !== 'object' || options === null) - throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); + throw new ERR_INVALID_ARG_TYPE('options', 'object', options); if (!ArrayIsArray(options.categories)) { throw new ERR_INVALID_ARG_TYPE('options.categories', 'string[]', diff --git a/lib/vm.js b/lib/vm.js index 03ff0fcd03ac..a4b5b37e83cf 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -371,7 +371,7 @@ function compileFunction(code, params, options = {}) { if (typeof extension !== 'object') { throw new ERR_INVALID_ARG_TYPE( `options.contextExtensions[${i}]`, - 'Object', + 'object', extension ); } diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 3b85291835cc..85eb1de5bf47 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -484,7 +484,7 @@ assert.throws(() => { { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "options" argument must be an instance of Object.' + + 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 of type function or an instance of' + - " Object, Error, or RegExp. Received type string ('Error message')" + 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,8 @@ common.expectsError( () => assert.throws(() => {}, input), { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "error" argument must be of type function or an instance ' + - 'of Object, Error, or RegExp.' + + message: 'The "error" argument must be of type function or ' + + 'an instance of Error, RegExp, or Object.' + common.invalidArgTypeHelper(input) } ); diff --git a/test/parallel/test-child-process-constructor.js b/test/parallel/test-child-process-constructor.js index 20e1709b07bd..9c5b09171c66 100644 --- a/test/parallel/test-child-process-constructor.js +++ b/test/parallel/test-child-process-constructor.js @@ -15,7 +15,7 @@ assert.strictEqual(typeof ChildProcess, 'function'); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be an instance of Object.' + + message: 'The "options" argument must be of type object.' + `${common.invalidArgTypeHelper(options)}` }); }); diff --git a/test/parallel/test-child-process-fork.js b/test/parallel/test-child-process-fork.js index aab2b236f6eb..a771f84e681f 100644 --- a/test/parallel/test-child-process-fork.js +++ b/test/parallel/test-child-process-fork.js @@ -51,8 +51,8 @@ assert.throws(() => n.send(), { assert.throws(() => n.send(Symbol()), { name: 'TypeError', - message: 'The "message" argument must be one of type string, number, or ' + - 'boolean or an instance of Object. Received type symbol (Symbol())', + message: 'The "message" argument must be one of type string,' + + ' 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 42ce6c27d342..0356690a4d34 100644 --- a/test/parallel/test-console-instance.js +++ b/test/parallel/test-console-instance.js @@ -140,7 +140,7 @@ out.write = err.write = (d) => {}; }); }, { - message: 'The "inspectOptions" argument must be an instance of Object.' + + message: 'The "inspectOptions" argument must be of type object.' + common.invalidArgTypeHelper(inspectOptions), code: 'ERR_INVALID_ARG_TYPE' } diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js index 3f47d1592f07..c8303431fb30 100644 --- a/test/parallel/test-crypto-key-objects.js +++ b/test/parallel/test-crypto-key-objects.js @@ -59,7 +59,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', type: TypeError, code: 'ERR_INVALID_ARG_TYPE', message: - 'The "handle" argument must be an instance of Object. Received type ' + + 'The "handle" argument must be of type object. Received type ' + "string ('')" }); } @@ -142,7 +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 an instance of Object/ + 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 6134bf71765c..605a3742052b 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -615,7 +615,7 @@ 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 an instance of Object. ' + + message: 'The "options" argument must be of type object. ' + 'Received undefined' }); @@ -624,7 +624,7 @@ 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 an instance of Object. ' + + message: 'The "options" argument must be of type object. ' + 'Received type number (0)' }); } diff --git a/test/parallel/test-fs-rmdir-recursive.js b/test/parallel/test-fs-rmdir-recursive.js index a5d6eef1515e..628bba5d6fc4 100644 --- a/test/parallel/test-fs-rmdir-recursive.js +++ b/test/parallel/test-fs-rmdir-recursive.js @@ -182,7 +182,7 @@ function removeAsync(dir) { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /^The "options" argument must be an instance of Object\./ + message: /^The "options" argument must be of type object\./ }); }); diff --git a/test/parallel/test-http2-createsecureserver-options.js b/test/parallel/test-http2-createsecureserver-options.js index 84d75e23b334..269239fcf287 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 6f3d4b569331..8814e2db9e88 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-misc-util.js b/test/parallel/test-http2-misc-util.js index 00a89c65b0eb..ec9c65ec088b 100644 --- a/test/parallel/test-http2-misc-util.js +++ b/test/parallel/test-http2-misc-util.js @@ -35,7 +35,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "test" argument must be an instance of Object. Received ' + + message: 'The "test" argument must be of type object. Received ' + "type string ('foo')" }); diff --git a/test/parallel/test-http2-util-asserts.js b/test/parallel/test-http2-util-asserts.js index d9bd588f63be..e80f7128378e 100644 --- a/test/parallel/test-http2-util-asserts.js +++ b/test/parallel/test-http2-util-asserts.js @@ -30,7 +30,7 @@ const { () => assertIsObject(input, 'foo', 'Object'), { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "foo" argument must be an instance of Object.' + + message: 'The "foo" argument must be of type object.' + common.invalidArgTypeHelper(input) }); }); diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index d0578d560220..9d616d0c130c 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -220,7 +220,7 @@ function checkFormat(path, testCases) { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "pathObject" argument must be an instance of Object.' + + message: 'The "pathObject" argument must be of type object.' + common.invalidArgTypeHelper(pathObject) }); }); diff --git a/test/parallel/test-performanceobserver.js b/test/parallel/test-performanceobserver.js index a37f0dc45e0d..6c28baa82f18 100644 --- a/test/parallel/test-performanceobserver.js +++ b/test/parallel/test-performanceobserver.js @@ -48,7 +48,7 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be an instance of Object.' + + 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 ed5f806ab06d..ecd782f86a52 100644 --- a/test/parallel/test-process-cpuUsage.js +++ b/test/parallel/test-process-cpuUsage.js @@ -38,7 +38,7 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "prevValue" argument must be an instance of Object. ' + + message: 'The "prevValue" argument must be of type object. ' + 'Received type number (1)' } ); diff --git a/test/parallel/test-tls-keyengine-invalid-arg-type.js b/test/parallel/test-tls-keyengine-invalid-arg-type.js index 385841a6541f..d68b40cf0dba 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 e969e6d54c06..ed24863a2a3c 100644 --- a/test/parallel/test-tls-no-cert-required.js +++ b/test/parallel/test-tls-no-cert-required.js @@ -44,7 +44,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be an instance of Object. ' + + message: 'The "options" argument must be of type object. ' + "Received type string ('this is not valid')" } ); diff --git a/test/parallel/test-url-format-invalid-input.js b/test/parallel/test-url-format-invalid-input.js index 4bc22bd43352..5ba3b0bb4bf2 100644 --- a/test/parallel/test-url-format-invalid-input.js +++ b/test/parallel/test-url-format-invalid-input.js @@ -19,8 +19,8 @@ for (const urlObject of throwsObjsAndReportTypes) { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "urlObject" argument must be of type string or an instance ' + - `of Object.${common.invalidArgTypeHelper(urlObject)}` + 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 827266079a73..ab3d18bdc3aa 100644 --- a/test/parallel/test-url-format-whatwg.js +++ b/test/parallel/test-url-format-whatwg.js @@ -27,7 +27,7 @@ assert.strictEqual( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "options" argument must be an instance of Object.' + + message: 'The "options" argument must be of type object.' + common.invalidArgTypeHelper(value) } ); diff --git a/test/parallel/test-util-inherits.js b/test/parallel/test-util-inherits.js index cae54b612b31..a190c8d8864a 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 an ' + - 'instance of Object. Received undefined' + message: 'The "superCtor.prototype" property must be of type object. ' + + 'Received undefined' }); common.expectsError(function() { diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index c43daccefffd..93a22743cec3 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1456,7 +1456,7 @@ if (typeof Symbol !== 'undefined') { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be an instance of Object. ' + + message: 'The "options" argument must be of type object. ' + 'Received null' } ); @@ -1466,7 +1466,7 @@ if (typeof Symbol !== 'undefined') { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be an instance of Object. ' + + message: 'The "options" argument must be of type object. ' + "Received type string ('bad')" } ); diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js index 38f345b63238..e530f671968c 100644 --- a/test/parallel/test-vm-basic.js +++ b/test/parallel/test-vm-basic.js @@ -102,7 +102,7 @@ const vm = require('vm'); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be an instance of Object.' + + message: 'The "options" argument must be of type object.' + common.invalidArgTypeHelper(input) }); }); @@ -246,8 +246,8 @@ const vm = require('vm'); }, { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options.contextExtensions[0]" property must be an instance' + - ' of Object. Received type number (0)' + message: 'The "options.contextExtensions[0]" property must be of type ' + + 'object. Received type number (0)' }); const oldLimit = Error.stackTraceLimit; diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index 9118b8155ba6..53326942d89d 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -67,7 +67,7 @@ assert.strictEqual(gh1140Exception.toString(), 'Error'); const nonContextualSandboxError = { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /must be an instance of Object/ + message: /must be of type object/ }; const contextifiedSandboxError = { code: 'ERR_INVALID_ARG_TYPE', diff --git a/test/parallel/test-vm-module-errors.js b/test/parallel/test-vm-module-errors.js index aaea483316f9..a76666c02835 100644 --- a/test/parallel/test-vm-module-errors.js +++ b/test/parallel/test-vm-module-errors.js @@ -80,7 +80,7 @@ async function checkModuleState() { await m.evaluate(false); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options" argument must be an instance of Object. ' + + message: 'The "options" argument must be of type object. ' + 'Received type boolean (false)' }); diff --git a/test/parallel/test-worker-process-env.js b/test/parallel/test-worker-process-env.js index 0a366289e880..1316afd78355 100644 --- a/test/parallel/test-worker-process-env.js +++ b/test/parallel/test-worker-process-env.js @@ -28,7 +28,7 @@ if (!workerData && process.argv[2] !== 'child') { }, { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options.env" property must be an instance of Object or ' + + message: 'The "options.env" property must be of type object or ' + 'one of undefined, null, or worker_threads.SHARE_ENV. Received type ' + 'number (42)' }); diff --git a/test/sequential/test-inspector-module.js b/test/sequential/test-inspector-module.js index 2d887518b891..166b726db4b8 100644 --- a/test/sequential/test-inspector-module.js +++ b/test/sequential/test-inspector-module.js @@ -41,7 +41,7 @@ session.post('Runtime.evaluate', { expression: '2 + 2' }); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "params" argument must be an instance of Object.' + + 'The "params" argument must be of type object.' + common.invalidArgTypeHelper(i) } ); From 0e7b9ff277b5f238be58b960d43be3a491ffce58 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 19 Dec 2019 20:32:20 +0100 Subject: [PATCH 4/4] fixup: errors: improve ERR_INVALID_ARG_TYPE Linter issue --- test/common/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/common/index.js b/test/common/index.js index 544ad7865692..a320a1bebfef 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -717,6 +717,7 @@ 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) {