From c6b6c92185316e13738e6fa931fdd5303e381e46 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 19 Mar 2018 13:33:46 +0100 Subject: lib: always show ERR_INVALID_ARG_TYPE received part This makes a effort to make sure all of these errors will actually also show the received input. On top of that it refactors a few tests for better maintainability. It will also change the returned type to always be a simple typeof instead of special handling null. PR-URL: https://github.com/nodejs/node/pull/19445 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Joyee Cheung Reviewed-By: Anna Henningsen --- lib/_http_outgoing.js | 9 +- lib/_stream_readable.js | 3 +- lib/_stream_writable.js | 2 +- lib/_tls_common.js | 7 +- lib/_tls_wrap.js | 4 +- lib/async_hooks.js | 2 +- lib/buffer.js | 28 +++-- lib/dgram.js | 22 ++-- lib/events.js | 8 +- lib/fs/promises.js | 2 +- lib/internal/crypto/certificate.js | 9 +- lib/internal/crypto/cipher.js | 35 +++--- lib/internal/crypto/diffiehellman.js | 10 +- lib/internal/crypto/hash.js | 9 +- lib/internal/crypto/pbkdf2.js | 12 +- lib/internal/crypto/random.js | 4 +- lib/internal/crypto/sig.js | 16 ++- lib/internal/crypto/util.js | 20 ++-- lib/internal/encoding.js | 8 +- lib/internal/errors.js | 10 +- lib/internal/fs.js | 5 +- lib/internal/http2/compat.js | 10 +- lib/internal/http2/core.js | 24 ++-- lib/internal/http2/util.js | 2 +- lib/internal/modules/esm/Loader.js | 6 +- lib/internal/modules/esm/ModuleMap.js | 8 +- lib/internal/process.js | 4 +- lib/internal/process/warning.js | 6 +- lib/internal/url.js | 2 +- lib/internal/util.js | 4 +- lib/internal/vm/Module.js | 3 +- lib/path.js | 6 +- lib/perf_hooks.js | 6 +- lib/string_decoder.js | 3 +- lib/util.js | 13 ++- lib/v8.js | 2 +- lib/zlib.js | 3 +- test/es-module/test-esm-loader-modulemap.js | 9 +- test/parallel/test-assert.js | 16 +-- test/parallel/test-buffer-compare.js | 17 +-- test/parallel/test-buffer-concat.js | 18 +-- test/parallel/test-child-process-constructor.js | 2 +- test/parallel/test-crypto-certificate.js | 39 +++---- test/parallel/test-crypto-cipher-decipher.js | 16 +-- test/parallel/test-crypto-cipheriv-decipheriv.js | 14 ++- test/parallel/test-crypto-dh.js | 9 +- test/parallel/test-crypto-engine.js | 4 +- test/parallel/test-crypto-hash.js | 3 +- test/parallel/test-crypto-hmac.js | 4 +- test/parallel/test-crypto-pbkdf2.js | 37 +++--- test/parallel/test-crypto-sign-verify.js | 124 ++++++--------------- test/parallel/test-dgram-custom-lookup.js | 3 +- test/parallel/test-dgram-send-address-types.js | 50 +++------ test/parallel/test-dgram-sendto.js | 66 +++++------ test/parallel/test-event-emitter-add-listeners.js | 3 +- 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-access.js | 3 +- test/parallel/test-fs-buffer.js | 3 +- test/parallel/test-fs-chmod.js | 49 +++----- test/parallel/test-fs-close-errors.js | 28 ++--- test/parallel/test-fs-read-type.js | 20 +++- test/parallel/test-fs-readfile-error.js | 3 +- test/parallel/test-fs-rename-type-check.js | 40 ++++--- test/parallel/test-fs-stat.js | 54 ++++----- test/parallel/test-fs-truncate.js | 36 +++--- test/parallel/test-fs-watch.js | 8 +- test/parallel/test-http-mutable-headers.js | 9 +- test/parallel/test-http-outgoing-proto.js | 6 +- .../test-http2-client-setNextStreamID-errors.js | 3 +- .../test-http2-compat-serverrequest-headers.js | 4 +- .../test-http2-compat-serverresponse-headers.js | 40 +++---- .../test-http2-compat-serverresponse-trailers.js | 5 +- .../test-http2-createsecureserver-nooptions.js | 18 +-- test/parallel/test-http2-getpackedsettings.js | 7 +- test/parallel/test-http2-invalidargtypes-errors.js | 3 +- test/parallel/test-http2-misc-util.js | 4 +- test/parallel/test-http2-ping.js | 8 +- test/parallel/test-http2-respond-file-fd-errors.js | 3 +- .../test-http2-server-shutdown-options-errors.js | 16 +-- test/parallel/test-http2-util-asserts.js | 7 +- test/parallel/test-https-options-boolean-check.js | 112 ++++++++++--------- test/parallel/test-icu-transcode.js | 2 +- test/parallel/test-internal-errors.js | 30 ----- test/parallel/test-net-connect-buffer.js | 8 +- test/parallel/test-path-parse-format.js | 6 +- test/parallel/test-performance-function.js | 7 +- test/parallel/test-performanceobserver.js | 8 +- .../test-process-exception-capture-errors.js | 3 +- test/parallel/test-process-kill-pid.js | 26 ++--- test/parallel/test-tls-basic-validations.js | 3 +- test/parallel/test-tls-error-servername.js | 3 +- test/parallel/test-tls-no-cert-required.js | 3 +- test/parallel/test-tls-options-boolean-check.js | 94 ++++++++-------- test/parallel/test-url-format-invalid-input.js | 2 +- test/parallel/test-url-format-whatwg.js | 20 ++-- test/parallel/test-url-parse-invalid-input.js | 2 +- test/parallel/test-util-callbackify.js | 6 +- test/parallel/test-util-deprecate-invalid-code.js | 3 +- test/parallel/test-util-inherits.js | 10 +- test/parallel/test-util-inspect.js | 6 +- test/parallel/test-util-promisify.js | 3 +- test/parallel/test-v8-flag-type-check.js | 7 +- test/parallel/test-vm-basic.js | 73 +++++------- test/parallel/test-zlib-not-string-or-buffer.js | 16 ++- test/sequential/test-crypto-timing-safe-equal.js | 6 +- 107 files changed, 748 insertions(+), 861 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 9cb9c29b36..2af2fddb62 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -540,7 +540,7 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) { OutgoingMessage.prototype.getHeader = function getHeader(name) { if (typeof name !== 'string') { - throw new ERR_INVALID_ARG_TYPE('name', 'string'); + throw new ERR_INVALID_ARG_TYPE('name', 'string', name); } if (!this[outHeadersKey]) return; @@ -576,7 +576,7 @@ OutgoingMessage.prototype.getHeaders = function getHeaders() { OutgoingMessage.prototype.hasHeader = function hasHeader(name) { if (typeof name !== 'string') { - throw new ERR_INVALID_ARG_TYPE('name', 'string'); + throw new ERR_INVALID_ARG_TYPE('name', 'string', name); } return !!(this[outHeadersKey] && this[outHeadersKey][name.toLowerCase()]); @@ -585,7 +585,7 @@ OutgoingMessage.prototype.hasHeader = function hasHeader(name) { OutgoingMessage.prototype.removeHeader = function removeHeader(name) { if (typeof name !== 'string') { - throw new ERR_INVALID_ARG_TYPE('name', 'string'); + throw new ERR_INVALID_ARG_TYPE('name', 'string', name); } if (this._header) { @@ -656,7 +656,8 @@ function write_(msg, chunk, encoding, callback, fromEnd) { } if (!fromEnd && typeof chunk !== 'string' && !(chunk instanceof Buffer)) { - throw new ERR_INVALID_ARG_TYPE('first argument', ['string', 'Buffer']); + throw new ERR_INVALID_ARG_TYPE('first argument', + ['string', 'Buffer'], chunk); } diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 434dabd883..0b6cf10aac 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -294,7 +294,8 @@ function chunkInvalid(state, chunk) { typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { - er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array']); + er = new ERR_INVALID_ARG_TYPE( + 'chunk', ['string', 'Buffer', 'Uint8Array'], chunk); } return er; } diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 5692cae195..df1d4076d0 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -255,7 +255,7 @@ function validChunk(stream, state, chunk, cb) { if (chunk === null) { er = new ERR_STREAM_NULL_VALUES(); } else if (typeof chunk !== 'string' && !state.objectMode) { - er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer']); + er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk); } if (er) { stream.emit('error', er); diff --git a/lib/_tls_common.js b/lib/_tls_common.js index f63acad8ad..b669badb70 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -58,11 +58,14 @@ function SecureContext(secureProtocol, secureOptions, context) { } function validateKeyCert(value, type) { - if (typeof value !== 'string' && !isArrayBufferView(value)) + if (typeof value !== 'string' && !isArrayBufferView(value)) { throw new ERR_INVALID_ARG_TYPE( + // TODO(BridgeAR): Change this to `options.${type}` type, - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + value ); + } } exports.SecureContext = SecureContext; diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 839aba555b..41dd001bd6 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -667,7 +667,7 @@ TLSSocket.prototype._start = function() { TLSSocket.prototype.setServername = function(name) { if (typeof name !== 'string') { - throw new ERR_INVALID_ARG_TYPE('name', 'string'); + throw new ERR_INVALID_ARG_TYPE('name', 'string', name); } if (this._tlsOptions.isServer) { @@ -877,7 +877,7 @@ function Server(options, listener) { } else if (options == null || typeof options === 'object') { options = options || {}; } else { - throw new ERR_INVALID_ARG_TYPE('options', 'Object'); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); } diff --git a/lib/async_hooks.js b/lib/async_hooks.js index 3a79da27da..345b003e54 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -141,7 +141,7 @@ function showEmitBeforeAfterWarning() { class AsyncResource { constructor(type, opts = {}) { if (typeof type !== 'string') - throw new ERR_INVALID_ARG_TYPE('type', 'string'); + throw new ERR_INVALID_ARG_TYPE('type', 'string', type); if (typeof opts === 'number') { opts = { triggerAsyncId: opts, requireManualDestroy: false }; diff --git a/lib/buffer.js b/lib/buffer.js index c11762aa57..a13ada73ce 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -416,16 +416,20 @@ Buffer.isBuffer = function isBuffer(b) { return b instanceof Buffer; }; -Buffer.compare = function compare(a, b) { - if (!isUint8Array(a) || !isUint8Array(b)) { - throw new ERR_INVALID_ARG_TYPE(['buf1', 'buf2'], ['Buffer', 'Uint8Array']); +Buffer.compare = function compare(buf1, buf2) { + if (!isUint8Array(buf1)) { + throw new ERR_INVALID_ARG_TYPE('buf1', ['Buffer', 'Uint8Array'], buf1); } - if (a === b) { + if (!isUint8Array(buf2)) { + throw new ERR_INVALID_ARG_TYPE('buf2', ['Buffer', 'Uint8Array'], buf2); + } + + if (buf1 === buf2) { return 0; } - return _compare(a, b); + return _compare(buf1, buf2); }; Buffer.isEncoding = function isEncoding(encoding) { @@ -437,7 +441,8 @@ Buffer[kIsEncodingSymbol] = Buffer.isEncoding; Buffer.concat = function concat(list, length) { var i; if (!Array.isArray(list)) { - throw new ERR_INVALID_ARG_TYPE('list', ['Array', 'Buffer', 'Uint8Array']); + throw new ERR_INVALID_ARG_TYPE( + 'list', ['Array', 'Buffer', 'Uint8Array'], list); } if (list.length === 0) @@ -645,14 +650,15 @@ Buffer.prototype.toString = function toString(encoding, start, end) { return stringSlice(this, encoding, start, end); }; -Buffer.prototype.equals = function equals(b) { - if (!isUint8Array(b)) { - throw new ERR_INVALID_ARG_TYPE('otherBuffer', ['Buffer', 'Uint8Array'], b); +Buffer.prototype.equals = function equals(otherBuffer) { + if (!isUint8Array(otherBuffer)) { + throw new ERR_INVALID_ARG_TYPE( + 'otherBuffer', ['Buffer', 'Uint8Array'], otherBuffer); } - if (this === b) + if (this === otherBuffer) return true; - return _compare(this, b) === 0; + return _compare(this, otherBuffer) === 0; }; // Override how buffers are presented by util.inspect(). diff --git a/lib/dgram.js b/lib/dgram.js index b9caeddabe..355e7d2fbe 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -75,7 +75,7 @@ function newHandle(type, lookup) { if (lookup === undefined) lookup = dns.lookup; else if (typeof lookup !== 'function') - throw new ERR_INVALID_ARG_TYPE('lookup', 'Function'); + throw new ERR_INVALID_ARG_TYPE('lookup', 'Function', lookup); if (type === 'udp4') { const handle = new UDP(); @@ -299,19 +299,19 @@ Socket.prototype.sendto = function(buffer, address, callback) { if (typeof offset !== 'number') { - throw new ERR_INVALID_ARG_TYPE('offset', 'number'); + throw new ERR_INVALID_ARG_TYPE('offset', 'number', offset); } if (typeof length !== 'number') { - throw new ERR_INVALID_ARG_TYPE('length', 'number'); + throw new ERR_INVALID_ARG_TYPE('length', 'number', length); } if (typeof port !== 'number') { - throw new ERR_INVALID_ARG_TYPE('port', 'number'); + throw new ERR_INVALID_ARG_TYPE('port', 'number', port); } if (typeof address !== 'string') { - throw new ERR_INVALID_ARG_TYPE('address', 'string'); + throw new ERR_INVALID_ARG_TYPE('address', 'string', address); } this.send(buffer, offset, length, port, address, callback); @@ -323,7 +323,7 @@ function sliceBuffer(buffer, offset, length) { buffer = Buffer.from(buffer); } else if (!isUint8Array(buffer)) { throw new ERR_INVALID_ARG_TYPE('buffer', - ['Buffer', 'Uint8Array', 'string']); + ['Buffer', 'Uint8Array', 'string'], buffer); } offset = offset >>> 0; @@ -415,13 +415,14 @@ Socket.prototype.send = function(buffer, list = [ Buffer.from(buffer) ]; } else if (!isUint8Array(buffer)) { throw new ERR_INVALID_ARG_TYPE('buffer', - ['Buffer', 'Uint8Array', 'string']); + ['Buffer', 'Uint8Array', 'string'], + buffer); } else { list = [ buffer ]; } } else if (!(list = fixBufferList(buffer))) { throw new ERR_INVALID_ARG_TYPE('buffer list arguments', - ['Buffer', 'string']); + ['Buffer', 'string'], buffer); } port = port >>> 0; @@ -437,7 +438,7 @@ Socket.prototype.send = function(buffer, callback = address; address = undefined; } else if (address && typeof address !== 'string') { - throw new ERR_INVALID_ARG_TYPE('address', ['string', 'falsy']); + throw new ERR_INVALID_ARG_TYPE('address', ['string', 'falsy'], address); } this._healthCheck(); @@ -602,7 +603,8 @@ Socket.prototype.setMulticastInterface = function(interfaceAddress) { this._healthCheck(); if (typeof interfaceAddress !== 'string') { - throw new ERR_INVALID_ARG_TYPE('interfaceAddress', 'string'); + throw new ERR_INVALID_ARG_TYPE( + 'interfaceAddress', 'string', interfaceAddress); } const err = this._handle.setMulticastInterface(interfaceAddress); diff --git a/lib/events.js b/lib/events.js index 46761653a0..46d1223e69 100644 --- a/lib/events.js +++ b/lib/events.js @@ -197,7 +197,7 @@ function _addListener(target, type, listener, prepend) { if (typeof listener !== 'function') { const errors = lazyErrors(); - throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function'); + throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function', listener); } events = target._events; @@ -287,7 +287,7 @@ function _onceWrap(target, type, listener) { EventEmitter.prototype.once = function once(type, listener) { if (typeof listener !== 'function') { const errors = lazyErrors(); - throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function'); + throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function', listener); } this.on(type, _onceWrap(this, type, listener)); return this; @@ -297,7 +297,7 @@ EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) { if (typeof listener !== 'function') { const errors = lazyErrors(); - throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function'); + throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function', listener); } this.prependListener(type, _onceWrap(this, type, listener)); return this; @@ -310,7 +310,7 @@ EventEmitter.prototype.removeListener = if (typeof listener !== 'function') { const errors = lazyErrors(); - throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function'); + throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function', listener); } events = this._events; diff --git a/lib/fs/promises.js b/lib/fs/promises.js index 8884777e5e..c3c3c3e4db 100644 --- a/lib/fs/promises.js +++ b/lib/fs/promises.js @@ -112,7 +112,7 @@ class FileHandle { function validateFileHandle(handle) { if (!(handle instanceof FileHandle)) - throw new ERR_INVALID_ARG_TYPE('filehandle', 'FileHandle'); + throw new ERR_INVALID_ARG_TYPE('filehandle', 'FileHandle', handle); } async function writeFileHandle(filehandle, data, options) { diff --git a/lib/internal/crypto/certificate.js b/lib/internal/crypto/certificate.js index 5eaa5ce056..35325874ba 100644 --- a/lib/internal/crypto/certificate.js +++ b/lib/internal/crypto/certificate.js @@ -17,7 +17,8 @@ function verifySpkac(spkac) { if (!isArrayBufferView(spkac)) { throw new ERR_INVALID_ARG_TYPE( 'spkac', - ['Buffer', 'TypedArray', 'DataView'] + ['Buffer', 'TypedArray', 'DataView'], + spkac ); } return certVerifySpkac(spkac); @@ -28,7 +29,8 @@ function exportPublicKey(spkac, encoding) { if (!isArrayBufferView(spkac)) { throw new ERR_INVALID_ARG_TYPE( 'spkac', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + spkac ); } return certExportPublicKey(spkac); @@ -39,7 +41,8 @@ function exportChallenge(spkac, encoding) { if (!isArrayBufferView(spkac)) { throw new ERR_INVALID_ARG_TYPE( 'spkac', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + spkac ); } return certExportChallenge(spkac); diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js index 73118ffebb..cd8297245f 100644 --- a/lib/internal/crypto/cipher.js +++ b/lib/internal/crypto/cipher.js @@ -67,13 +67,14 @@ function Cipher(cipher, password, options) { return new Cipher(cipher, password, options); if (typeof cipher !== 'string') - throw new ERR_INVALID_ARG_TYPE('cipher', 'string'); + throw new ERR_INVALID_ARG_TYPE('cipher', 'string', cipher); password = toBuf(password); if (!isArrayBufferView(password)) { throw new ERR_INVALID_ARG_TYPE( 'password', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + password ); } @@ -110,7 +111,8 @@ Cipher.prototype.update = function update(data, inputEncoding, outputEncoding) { if (typeof data !== 'string' && !isArrayBufferView(data)) { throw new ERR_INVALID_ARG_TYPE( 'data', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + data ); } @@ -155,7 +157,8 @@ Cipher.prototype.getAuthTag = function getAuthTag() { Cipher.prototype.setAuthTag = function setAuthTag(tagbuf) { if (!isArrayBufferView(tagbuf)) { throw new ERR_INVALID_ARG_TYPE('buffer', - ['Buffer', 'TypedArray', 'DataView']); + ['Buffer', 'TypedArray', 'DataView'], + tagbuf); } // Do not do a normal falsy check because the method returns // undefined if it succeeds. Returns false specifically if it @@ -168,7 +171,8 @@ Cipher.prototype.setAuthTag = function setAuthTag(tagbuf) { Cipher.prototype.setAAD = function setAAD(aadbuf) { if (!isArrayBufferView(aadbuf)) { throw new ERR_INVALID_ARG_TYPE('buffer', - ['Buffer', 'TypedArray', 'DataView']); + ['Buffer', 'TypedArray', 'DataView'], + aadbuf); } if (this._handle.setAAD(aadbuf) === false) throw new ERR_CRYPTO_INVALID_STATE('setAAD'); @@ -180,13 +184,14 @@ function Cipheriv(cipher, key, iv, options) { return new Cipheriv(cipher, key, iv, options); if (typeof cipher !== 'string') - throw new ERR_INVALID_ARG_TYPE('cipher', 'string'); + throw new ERR_INVALID_ARG_TYPE('cipher', 'string', cipher); key = toBuf(key); if (!isArrayBufferView(key)) { throw new ERR_INVALID_ARG_TYPE( 'key', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + key ); } @@ -194,7 +199,8 @@ function Cipheriv(cipher, key, iv, options) { if (iv !== null && !isArrayBufferView(iv)) { throw new ERR_INVALID_ARG_TYPE( 'iv', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + iv ); } @@ -226,13 +232,14 @@ function Decipher(cipher, password, options) { return new Decipher(cipher, password, options); if (typeof cipher !== 'string') - throw new ERR_INVALID_ARG_TYPE('cipher', 'string'); + throw new ERR_INVALID_ARG_TYPE('cipher', 'string', cipher); password = toBuf(password); if (!isArrayBufferView(password)) { throw new ERR_INVALID_ARG_TYPE( 'password', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + password ); } @@ -261,13 +268,14 @@ function Decipheriv(cipher, key, iv, options) { return new Decipheriv(cipher, key, iv, options); if (typeof cipher !== 'string') - throw new ERR_INVALID_ARG_TYPE('cipher', 'string'); + throw new ERR_INVALID_ARG_TYPE('cipher', 'string', cipher); key = toBuf(key); if (!isArrayBufferView(key)) { throw new ERR_INVALID_ARG_TYPE( 'key', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + key ); } @@ -275,7 +283,8 @@ function Decipheriv(cipher, key, iv, options) { if (iv !== null && !isArrayBufferView(iv)) { throw new ERR_INVALID_ARG_TYPE( 'iv', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + iv ); } diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index 793f3fb351..527d8b07e1 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -34,7 +34,8 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) { !isArrayBufferView(sizeOrKey)) { throw new ERR_INVALID_ARG_TYPE( 'sizeOrKey', - ['number', 'string', 'Buffer', 'TypedArray', 'DataView'] + ['number', 'string', 'Buffer', 'TypedArray', 'DataView'], + sizeOrKey ); } @@ -169,7 +170,7 @@ function ECDH(curve) { return new ECDH(curve); if (typeof curve !== 'string') - throw new ERR_INVALID_ARG_TYPE('curve', 'string'); + throw new ERR_INVALID_ARG_TYPE('curve', 'string', curve); this._handle = new _ECDH(curve); } @@ -196,12 +197,13 @@ ECDH.convertKey = function convertKey(key, curve, inEnc, outEnc, format) { if (typeof key !== 'string' && !isArrayBufferView(key)) { throw new ERR_INVALID_ARG_TYPE( 'key', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + key ); } if (typeof curve !== 'string') { - throw new ERR_INVALID_ARG_TYPE('curve', 'string'); + throw new ERR_INVALID_ARG_TYPE('curve', 'string', curve); } const encoding = getDefaultEncoding(); diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index 41e00b88b9..d172a6a3c8 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -29,7 +29,7 @@ function Hash(algorithm, options) { if (!(this instanceof Hash)) return new Hash(algorithm, options); if (typeof algorithm !== 'string') - throw new ERR_INVALID_ARG_TYPE('algorithm', 'string'); + throw new ERR_INVALID_ARG_TYPE('algorithm', 'string', algorithm); this._handle = new _Hash(algorithm); this[kState] = { [kFinalized]: false @@ -56,7 +56,7 @@ Hash.prototype.update = function update(data, encoding) { if (typeof data !== 'string' && !isArrayBufferView(data)) { throw new ERR_INVALID_ARG_TYPE('data', - ['string', 'TypedArray', 'DataView']); + ['string', 'TypedArray', 'DataView'], data); } if (!this._handle.update(data, encoding || getDefaultEncoding())) @@ -84,9 +84,10 @@ function Hmac(hmac, key, options) { if (!(this instanceof Hmac)) return new Hmac(hmac, key, options); if (typeof hmac !== 'string') - throw new ERR_INVALID_ARG_TYPE('hmac', 'string'); + throw new ERR_INVALID_ARG_TYPE('hmac', 'string', hmac); if (typeof key !== 'string' && !isArrayBufferView(key)) { - throw new ERR_INVALID_ARG_TYPE('key', ['string', 'TypedArray', 'DataView']); + throw new ERR_INVALID_ARG_TYPE('key', + ['string', 'TypedArray', 'DataView'], key); } this._handle = new _Hmac(); this._handle.init(hmac, toBuf(key)); diff --git a/lib/internal/crypto/pbkdf2.js b/lib/internal/crypto/pbkdf2.js index fdffcffad6..de41be4228 100644 --- a/lib/internal/crypto/pbkdf2.js +++ b/lib/internal/crypto/pbkdf2.js @@ -37,22 +37,24 @@ function pbkdf2Sync(password, salt, iterations, keylen, digest) { function _pbkdf2(password, salt, iterations, keylen, digest, callback) { if (digest !== null && typeof digest !== 'string') - throw new ERR_INVALID_ARG_TYPE('digest', ['string', 'null']); + throw new ERR_INVALID_ARG_TYPE('digest', ['string', 'null'], digest); password = toBuf(password); salt = toBuf(salt); if (!isArrayBufferView(password)) { throw new ERR_INVALID_ARG_TYPE('password', - ['string', 'Buffer', 'TypedArray']); + ['string', 'Buffer', 'TypedArray'], + password); } if (!isArrayBufferView(salt)) { - throw new ERR_INVALID_ARG_TYPE('salt', ['string', 'Buffer', 'TypedArray']); + throw new ERR_INVALID_ARG_TYPE('salt', + ['string', 'Buffer', 'TypedArray'], salt); } if (typeof iterations !== 'number') - throw new ERR_INVALID_ARG_TYPE('iterations', 'number'); + throw new ERR_INVALID_ARG_TYPE('iterations', 'number', iterations); if (iterations < 0) throw new ERR_OUT_OF_RANGE('iterations', @@ -60,7 +62,7 @@ function _pbkdf2(password, salt, iterations, keylen, digest, callback) { iterations); if (typeof keylen !== 'number') - throw new ERR_INVALID_ARG_TYPE('keylen', 'number'); + throw new ERR_INVALID_ARG_TYPE('keylen', 'number', keylen); if (keylen < 0 || !Number.isFinite(keylen) || diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index 77ad06ee7b..95e38dcc44 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -51,7 +51,7 @@ function randomBytes(size, cb) { function randomFillSync(buf, offset = 0, size) { if (!isArrayBufferView(buf)) { - throw new ERR_INVALID_ARG_TYPE('buf', 'ArrayBufferView'); + throw new ERR_INVALID_ARG_TYPE('buf', 'ArrayBufferView', buf); } const elementSize = buf.BYTES_PER_ELEMENT || 1; @@ -72,7 +72,7 @@ function randomFillSync(buf, offset = 0, size) { function randomFill(buf, offset, size, cb) { if (!isArrayBufferView(buf)) { - throw new ERR_INVALID_ARG_TYPE('buf', 'ArrayBufferView'); + throw new ERR_INVALID_ARG_TYPE('buf', 'ArrayBufferView', buf); } const elementSize = buf.BYTES_PER_ELEMENT || 1; diff --git a/lib/internal/crypto/sig.js b/lib/internal/crypto/sig.js index 688ad43ddd..aed679e99b 100644 --- a/lib/internal/crypto/sig.js +++ b/lib/internal/crypto/sig.js @@ -25,7 +25,7 @@ function Sign(algorithm, options) { if (!(this instanceof Sign)) return new Sign(algorithm, options); if (typeof algorithm !== 'string') - throw new ERR_INVALID_ARG_TYPE('algorithm', 'string'); + throw new ERR_INVALID_ARG_TYPE('algorithm', 'string', algorithm); this._handle = new _Sign(); this._handle.init(algorithm); @@ -45,7 +45,8 @@ Sign.prototype.update = function update(data, encoding) { if (!isArrayBufferView(data)) { throw new ERR_INVALID_ARG_TYPE( 'data', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + data ); } this._handle.update(data); @@ -82,7 +83,8 @@ Sign.prototype.sign = function sign(options, encoding) { if (!isArrayBufferView(key)) { throw new ERR_INVALID_ARG_TYPE( 'key', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + key ); } @@ -100,7 +102,7 @@ function Verify(algorithm, options) { if (!(this instanceof Verify)) return new Verify(algorithm, options); if (typeof algorithm !== 'string') - throw new ERR_INVALID_ARG_TYPE('algorithm', 'string'); + throw new ERR_INVALID_ARG_TYPE('algorithm', 'string', algorithm); this._handle = new _Verify(); this._handle.init(algorithm); @@ -139,7 +141,8 @@ Verify.prototype.verify = function verify(options, signature, sigEncoding) { if (!isArrayBufferView(key)) { throw new ERR_INVALID_ARG_TYPE( 'key', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + key ); } @@ -147,7 +150,8 @@ Verify.prototype.verify = function verify(options, signature, sigEncoding) { if (!isArrayBufferView(signature)) { throw new ERR_INVALID_ARG_TYPE( 'signature', - ['string', 'Buffer', 'TypedArray', 'DataView'] + ['string', 'Buffer', 'TypedArray', 'DataView'], + signature ); } diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index 19c35ac4cd..095ca0478b 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -54,10 +54,10 @@ const getCurves = cachedResult(() => filterDuplicateStrings(_getCurves())); function setEngine(id, flags) { if (typeof id !== 'string') - throw new ERR_INVALID_ARG_TYPE('id', 'string'); + throw new ERR_INVALID_ARG_TYPE('id', 'string', id); if (flags && typeof flags !== 'number') - throw new ERR_INVALID_ARG_TYPE('flags', 'number'); + throw new ERR_INVALID_ARG_TYPE('flags', 'number', flags); flags = flags >>> 0; // Use provided engine for everything by default @@ -68,17 +68,19 @@ function setEngine(id, flags) { throw new ERR_CRYPTO_ENGINE_UNKNOWN(id); } -function timingSafeEqual(a, b) { - if (!isArrayBufferView(a)) { - throw new ERR_INVALID_ARG_TYPE('a', ['Buffer', 'TypedArray', 'DataView']); +function timingSafeEqual(buf1, buf2) { + if (!isArrayBufferView(buf1)) { + throw new ERR_INVALID_ARG_TYPE('buf1', + ['Buffer', 'TypedArray', 'DataView'], buf1); } - if (!isArrayBufferView(b)) { - throw new ERR_INVALID_ARG_TYPE('b', ['Buffer', 'TypedArray', 'DataView']); + if (!isArrayBufferView(buf2)) { + throw new ERR_INVALID_ARG_TYPE('buf2', + ['Buffer', 'TypedArray', 'DataView'], buf2); } - if (a.length !== b.length) { + if (buf1.length !== buf2.length) { throw new ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH(); } - return _timingSafeEqual(a, b); + return _timingSafeEqual(buf1, buf2); } module.exports = { diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index 9cd47f861f..ae874c530c 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -51,7 +51,7 @@ function validateDecoder(obj) { function validateArgument(prop, expected, propName, expectedName) { if (typeof prop !== expected) - throw new ERR_INVALID_ARG_TYPE(propName, expectedName); + throw new ERR_INVALID_ARG_TYPE(propName, expectedName, prop); } const CONVERTER_FLAGS_FLUSH = 0x1; @@ -391,7 +391,8 @@ function makeTextDecoderICU() { input = lazyBuffer().from(input); } else if (!isArrayBufferView(input)) { throw new ERR_INVALID_ARG_TYPE('input', - ['ArrayBuffer', 'ArrayBufferView']); + ['ArrayBuffer', 'ArrayBufferView'], + input); } validateArgument(options, 'object', 'options', 'Object'); @@ -460,7 +461,8 @@ function makeTextDecoderJS() { input.byteLength); } else { throw new ERR_INVALID_ARG_TYPE('input', - ['ArrayBuffer', 'ArrayBufferView']); + ['ArrayBuffer', 'ArrayBufferView'], + input); } validateArgument(options, 'object', 'options', 'Object'); diff --git a/lib/internal/errors.js b/lib/internal/errors.js index ee7b78b66b..9487a84e03 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -319,7 +319,7 @@ function createErrDiff(actual, expected, operator) { class AssertionError extends Error { constructor(options) { if (typeof options !== 'object' || options === null) { - throw new codes.ERR_INVALID_ARG_TYPE('options', 'Object'); + throw new codes.ERR_INVALID_ARG_TYPE('options', 'Object', options); } var { actual, @@ -959,10 +959,10 @@ function invalidArgType(name, expected, actual) { msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, 'type')}`; } - // if actual value received, output it - if (arguments.length >= 3) { - msg += `. Received type ${actual !== null ? typeof actual : 'null'}`; - } + // If actual value received, output it + // TODO(BridgeAR): Improve the output by showing `null` and similar. + if (arguments.length === 3) + msg += `. Received type ${typeof actual}`; return msg; } diff --git a/lib/internal/fs.js b/lib/internal/fs.js index 36155d4d67..21ab1048d7 100644 --- a/lib/internal/fs.js +++ b/lib/internal/fs.js @@ -323,7 +323,8 @@ function toUnixTimestamp(time, name = 'time') { function validateBuffer(buffer) { if (!isUint8Array(buffer)) { - const err = new ERR_INVALID_ARG_TYPE('buffer', ['Buffer', 'Uint8Array']); + const err = new ERR_INVALID_ARG_TYPE('buffer', + ['Buffer', 'Uint8Array'], buffer); Error.captureStackTrace(err, validateBuffer); throw err; } @@ -379,7 +380,7 @@ function validatePath(path, propName) { } if (typeof path !== 'string' && !isUint8Array(path)) { - err = new ERR_INVALID_ARG_TYPE(propName, ['string', 'Buffer', 'URL']); + err = new ERR_INVALID_ARG_TYPE(propName, ['string', 'Buffer', 'URL'], path); } else { err = nullCheck(path, propName, false); } diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 6ec6cb33cb..78fedcb2ce 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -438,7 +438,7 @@ class Http2ServerResponse extends Stream { setTrailer(name, value) { if (typeof name !== 'string') - throw new ERR_INVALID_ARG_TYPE('name', 'string'); + throw new ERR_INVALID_ARG_TYPE('name', 'string', name); name = name.trim().toLowerCase(); assertValidHeader(name, value); @@ -456,7 +456,7 @@ class Http2ServerResponse extends Stream { getHeader(name) { if (typeof name !== 'string') - throw new ERR_INVALID_ARG_TYPE('name', 'string'); + throw new ERR_INVALID_ARG_TYPE('name', 'string', name); name = name.trim().toLowerCase(); return this[kHeaders][name]; @@ -472,7 +472,7 @@ class Http2ServerResponse extends Stream { hasHeader(name) { if (typeof name !== 'string') - throw new ERR_INVALID_ARG_TYPE('name', 'string'); + throw new ERR_INVALID_ARG_TYPE('name', 'string', name); name = name.trim().toLowerCase(); return Object.prototype.hasOwnProperty.call(this[kHeaders], name); @@ -480,7 +480,7 @@ class Http2ServerResponse extends Stream { removeHeader(name) { if (typeof name !== 'string') - throw new ERR_INVALID_ARG_TYPE('name', 'string'); + throw new ERR_INVALID_ARG_TYPE('name', 'string', name); if (this[kStream].headersSent) throw new ERR_HTTP2_HEADERS_SENT(); @@ -491,7 +491,7 @@ class Http2ServerResponse extends Stream { setHeader(name, value) { if (typeof name !== 'string') - throw new ERR_INVALID_ARG_TYPE('name', 'string'); + throw new ERR_INVALID_ARG_TYPE('name', 'string', name); if (this[kStream].headersSent) throw new ERR_HTTP2_HEADERS_SENT(); diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 9978df87d6..89cc8db0b0 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -984,7 +984,7 @@ class Http2Session extends EventEmitter { throw new ERR_HTTP2_INVALID_SESSION(); if (typeof id !== 'number') - throw new ERR_INVALID_ARG_TYPE('id', 'number'); + throw new ERR_INVALID_ARG_TYPE('id', 'number', id); if (id <= 0 || id > kMaxStreams) throw new ERR_OUT_OF_RANGE('id', `> 0 and <= ${kMaxStreams}`, id); this[kHandle].setNextStreamID(id); @@ -1003,7 +1003,8 @@ class Http2Session extends EventEmitter { } if (payload && !isArrayBufferView(payload)) { throw new ERR_INVALID_ARG_TYPE('payload', - ['Buffer', 'TypedArray', 'DataView']); + ['Buffer', 'TypedArray', 'DataView'], + payload); } if (payload && payload.length !== 8) { throw new ERR_HTTP2_PING_LENGTH(); @@ -1122,13 +1123,14 @@ class Http2Session extends EventEmitter { if (opaqueData !== undefined && !isArrayBufferView(opaqueData)) { throw new ERR_INVALID_ARG_TYPE('opaqueData', - ['Buffer', 'TypedArray', 'DataView']); + ['Buffer', 'TypedArray', 'DataView'], + opaqueData); } if (typeof code !== 'number') { - throw new ERR_INVALID_ARG_TYPE('code', 'number'); + throw new ERR_INVALID_ARG_TYPE('code', 'number', code); } if (typeof lastStreamID !== 'number') { - throw new ERR_INVALID_ARG_TYPE('lastStreamID', 'number'); + throw new ERR_INVALID_ARG_TYPE('lastStreamID', 'number', lastStreamID); } const goawayFn = submitGoaway.bind(this, code, lastStreamID, opaqueData); @@ -1321,14 +1323,15 @@ 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(); } } if (typeof alt !== 'string') - throw new ERR_INVALID_ARG_TYPE('alt', 'string'); + throw new ERR_INVALID_ARG_TYPE('alt', 'string', alt); if (!kQuotedString.test(alt)) throw new ERR_INVALID_CHAR('alt'); @@ -1794,7 +1797,7 @@ class Http2Stream extends Duplex { // but no DATA and HEADERS frames may be sent. close(code = NGHTTP2_NO_ERROR, callback) { if (typeof code !== 'number') - throw new ERR_INVALID_ARG_TYPE('code', 'number'); + throw new ERR_INVALID_ARG_TYPE('code', 'number', code); if (code < 0 || code > kMaxInt) throw new ERR_OUT_OF_RANGE('code'); if (callback !== undefined && typeof callback !== 'function') @@ -2313,7 +2316,7 @@ class ServerHttp2Stream extends Http2Stream { } if (typeof fd !== 'number') - throw new ERR_INVALID_ARG_TYPE('fd', 'number'); + throw new ERR_INVALID_ARG_TYPE('fd', 'number', fd); debug(`Http2Stream ${this[kID]} [Http2Session ` + `${sessionName(session[kType])}]: initiating response from fd`); @@ -2767,7 +2770,8 @@ function getPackedSettings(settings) { function getUnpackedSettings(buf, options = {}) { if (!isArrayBufferView(buf)) { - throw new ERR_INVALID_ARG_TYPE('buf', ['Buffer', 'TypedArray', 'DataView']); + throw new ERR_INVALID_ARG_TYPE('buf', + ['Buffer', 'TypedArray', 'DataView'], buf); } if (buf.length % 6 !== 0) throw new ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH(); diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index b9bd580af2..bf5d072193 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -482,7 +482,7 @@ function assertIsObject(value, name, types = 'Object') { (value === null || typeof value !== 'object' || Array.isArray(value))) { - const err = new ERR_INVALID_ARG_TYPE(name, types); + const err = new ERR_INVALID_ARG_TYPE(name, types, value); Error.captureStackTrace(err, assertIsObject); throw err; } diff --git a/lib/internal/modules/esm/Loader.js b/lib/internal/modules/esm/Loader.js index 84c23cc10a..e10296cce2 100644 --- a/lib/internal/modules/esm/Loader.js +++ b/lib/internal/modules/esm/Loader.js @@ -49,16 +49,16 @@ class Loader { async resolve(specifier, parentURL) { const isMain = parentURL === undefined; if (!isMain && typeof parentURL !== 'string') - throw new ERR_INVALID_ARG_TYPE('parentURL', 'string'); + throw new ERR_INVALID_ARG_TYPE('parentURL', 'string', parentURL); const { url, format } = await this._resolve(specifier, parentURL, defaultResolve); if (typeof url !== 'string') - throw new ERR_INVALID_ARG_TYPE('url', 'string'); + throw new ERR_INVALID_ARG_TYPE('url', 'string', url); if (typeof format !== 'string') - throw new ERR_INVALID_ARG_TYPE('format', 'string'); + throw new ERR_INVALID_ARG_TYPE('format', 'string', format); if (format === 'builtin') return { url: `node:${url}`, format }; diff --git a/lib/internal/modules/esm/ModuleMap.js b/lib/internal/modules/esm/ModuleMap.js index e9a8d22d7b..985d24dc8d 100644 --- a/lib/internal/modules/esm/ModuleMap.js +++ b/lib/internal/modules/esm/ModuleMap.js @@ -9,23 +9,23 @@ const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; class ModuleMap extends SafeMap { get(url) { if (typeof url !== 'string') { - throw new ERR_INVALID_ARG_TYPE('url', 'string'); + throw new ERR_INVALID_ARG_TYPE('url', 'string', url); } return super.get(url); } set(url, job) { if (typeof url !== 'string') { - throw new ERR_INVALID_ARG_TYPE('url', 'string'); + throw new ERR_INVALID_ARG_TYPE('url', 'string', url); } if (job instanceof ModuleJob !== true) { - throw new ERR_INVALID_ARG_TYPE('job', 'ModuleJob'); + throw new ERR_INVALID_ARG_TYPE('job', 'ModuleJob', job); } debug(`Storing ${url} in ModuleMap`); return super.set(url, job); } has(url) { if (typeof url !== 'string') { - throw new ERR_INVALID_ARG_TYPE('url', 'string'); + throw new ERR_INVALID_ARG_TYPE('url', 'string', url); } return super.has(url); } diff --git a/lib/internal/process.js b/lib/internal/process.js index 573ffc1600..f1224665c5 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -157,7 +157,7 @@ function setupKillAndExit() { // eslint-disable-next-line eqeqeq if (pid != (pid | 0)) { - throw new ERR_INVALID_ARG_TYPE('pid', 'number'); + throw new ERR_INVALID_ARG_TYPE('pid', 'number', pid); } // preserve null signal @@ -255,7 +255,7 @@ function setupUncaughtExceptionCapture(exceptionHandlerState) { return; } if (typeof fn !== 'function') { - throw new ERR_INVALID_ARG_TYPE('fn', ['Function', 'null']); + throw new ERR_INVALID_ARG_TYPE('fn', ['Function', 'null'], fn); } if (exceptionHandlerState.captureFn !== null) { throw new ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET(); diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 8c0a503239..a970b622c8 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -122,9 +122,9 @@ function setupProcessWarnings() { code = undefined; } if (code !== undefined && typeof code !== 'string') - throw new ERR_INVALID_ARG_TYPE('code', 'string'); + throw new ERR_INVALID_ARG_TYPE('code', 'string', code); if (type !== undefined && typeof type !== 'string') - throw new ERR_INVALID_ARG_TYPE('type', 'string'); + throw new ERR_INVALID_ARG_TYPE('type', 'string', type); if (warning === undefined || typeof warning === 'string') { // eslint-disable-next-line no-restricted-syntax warning = new Error(warning); @@ -134,7 +134,7 @@ function setupProcessWarnings() { Error.captureStackTrace(warning, ctor || process.emitWarning); } if (!(warning instanceof Error)) { - throw new ERR_INVALID_ARG_TYPE('warning', ['Error', 'string']); + throw new ERR_INVALID_ARG_TYPE('warning', ['Error', 'string'], warning); } if (warning.name === 'DeprecationWarning') { if (process.noDeprecation) diff --git a/lib/internal/url.js b/lib/internal/url.js index 0579cac16c..239a17e483 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -379,7 +379,7 @@ Object.defineProperties(URL.prototype, { // eslint-disable-next-line func-name-matching value: function format(options) { if (options && typeof options !== 'object') - throw new ERR_INVALID_ARG_TYPE('options', 'Object'); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); options = util._extend({ fragment: true, unicode: false, diff --git a/lib/internal/util.js b/lib/internal/util.js index 89bba47c90..247ac2dd5a 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -49,7 +49,7 @@ function deprecate(fn, msg, code) { } if (code !== undefined && typeof code !== 'string') - throw new ERR_INVALID_ARG_TYPE('code', 'string'); + throw new ERR_INVALID_ARG_TYPE('code', 'string', code); let warned = false; function deprecated(...args) { @@ -294,7 +294,7 @@ const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs'); function promisify(original) { if (typeof original !== 'function') - throw new ERR_INVALID_ARG_TYPE('original', 'Function'); + throw new ERR_INVALID_ARG_TYPE('original', 'Function', original); if (original[kCustomPromisifiedSymbol]) { const fn = original[kCustomPromisifiedSymbol]; diff --git a/lib/internal/vm/Module.js b/lib/internal/vm/Module.js index feb4bb190f..48d591f3bf 100644 --- a/lib/internal/vm/Module.js +++ b/lib/internal/vm/Module.js @@ -58,7 +58,8 @@ class Module { if (isContext(options.context)) { context = options.context; } else { - throw new ERR_INVALID_ARG_TYPE('options.context', 'vm.Context'); + throw new ERR_INVALID_ARG_TYPE('options.context', + 'vm.Context', options.context); } } diff --git a/lib/path.js b/lib/path.js index 427d158e7a..90129f1f52 100644 --- a/lib/path.js +++ b/lib/path.js @@ -36,7 +36,7 @@ const { function assertPath(path) { if (typeof path !== 'string') { - throw new ERR_INVALID_ARG_TYPE('path', 'string'); + throw new ERR_INVALID_ARG_TYPE('path', 'string', path); } } @@ -747,7 +747,7 @@ const win32 = { basename: function basename(path, ext) { if (ext !== undefined && typeof ext !== 'string') - throw new ERR_INVALID_ARG_TYPE('ext', 'string'); + throw new ERR_INVALID_ARG_TYPE('ext', 'string', ext); assertPath(path); var start = 0; var end = -1; @@ -1295,7 +1295,7 @@ const posix = { basename: function basename(path, ext) { if (ext !== undefined && typeof ext !== 'string') - throw new ERR_INVALID_ARG_TYPE('ext', 'string'); + throw new ERR_INVALID_ARG_TYPE('ext', 'string', ext); assertPath(path); var start = 0; diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index e4c2a985e4..7fa5501b28 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -383,7 +383,7 @@ class PerformanceObserver extends AsyncResource { observe(options) { const errors = lazyErrors(); if (typeof options !== 'object' || options == null) { - throw new errors.ERR_INVALID_ARG_TYPE('options', 'Object'); + throw new errors.ERR_INVALID_ARG_TYPE('options', 'Object', options); } if (!Array.isArray(options.entryTypes)) { throw new errors.ERR_INVALID_OPT_VALUE('entryTypes', options); @@ -420,7 +420,7 @@ class Performance extends PerformanceObserverEntryList { set maxEntries(val) { if (typeof val !== 'number' || val >>> 0 !== val) { const errors = lazyErrors(); - throw new errors.ERR_INVALID_ARG_TYPE('val', 'number'); + throw new errors.ERR_INVALID_ARG_TYPE('val', 'number', val); } this[kMaxCount] = Math.max(1, val >>> 0); } @@ -533,7 +533,7 @@ class Performance extends PerformanceObserverEntryList { timerify(fn) { if (typeof fn !== 'function') { const errors = lazyErrors(); - throw new errors.ERR_INVALID_ARG_TYPE('fn', 'Function'); + throw new errors.ERR_INVALID_ARG_TYPE('fn', 'Function', fn); } if (fn[kTimerified]) return fn[kTimerified]; diff --git a/lib/string_decoder.js b/lib/string_decoder.js index a6ae64c062..b32249ad9e 100644 --- a/lib/string_decoder.js +++ b/lib/string_decoder.js @@ -73,7 +73,8 @@ StringDecoder.prototype.write = function write(buf) { return buf; if (!ArrayBuffer.isView(buf)) throw new ERR_INVALID_ARG_TYPE('buf', - ['Buffer', 'Uint8Array', 'ArrayBufferView']); + ['Buffer', 'Uint8Array', 'ArrayBufferView'], + buf); return decode(this[kNativeDecoder], buf); }; diff --git a/lib/util.js b/lib/util.js index eabdf6c1df..2cf79bb5f0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -323,7 +323,7 @@ Object.defineProperty(inspect, 'defaultOptions', { }, set(options) { if (options === null || typeof options !== 'object') { - throw new ERR_INVALID_ARG_TYPE('options', 'Object'); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); } return _extend(inspectDefaultOptions, options); } @@ -1024,13 +1024,14 @@ function log() { function inherits(ctor, superCtor) { if (ctor === undefined || ctor === null) - throw new ERR_INVALID_ARG_TYPE('ctor', 'Function'); + throw new ERR_INVALID_ARG_TYPE('ctor', 'Function', ctor); if (superCtor === undefined || superCtor === null) - throw new ERR_INVALID_ARG_TYPE('superCtor', 'Function'); + throw new ERR_INVALID_ARG_TYPE('superCtor', 'Function', superCtor); if (superCtor.prototype === undefined) { - throw new ERR_INVALID_ARG_TYPE('superCtor.prototype', 'Function'); + throw new ERR_INVALID_ARG_TYPE('superCtor.prototype', + 'Function', superCtor.prototype); } ctor.super_ = superCtor; Object.setPrototypeOf(ctor.prototype, superCtor.prototype); @@ -1088,7 +1089,7 @@ function callbackifyOnRejected(reason, cb) { function callbackify(original) { if (typeof original !== 'function') { - throw new ERR_INVALID_ARG_TYPE('original', 'Function'); + throw new ERR_INVALID_ARG_TYPE('original', 'Function', original); } // We DO NOT return the promise as it gives the user a false sense that @@ -1097,7 +1098,7 @@ function callbackify(original) { function callbackified(...args) { const maybeCb = args.pop(); if (typeof maybeCb !== 'function') { - throw new ERR_INVALID_ARG_TYPE('last argument', 'Function'); + throw new ERR_INVALID_ARG_TYPE('last argument', 'Function', maybeCb); } const cb = (...args) => { Reflect.apply(maybeCb, this, args); }; // In true node style we process the callback on `nextTick` with all the diff --git a/lib/v8.js b/lib/v8.js index 0e2a6533dc..cce77c5062 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -67,7 +67,7 @@ const heapSpaceStatisticsBuffer = function setFlagsFromString(flags) { if (typeof flags !== 'string') - throw new ERR_INVALID_ARG_TYPE('flags', 'string'); + throw new ERR_INVALID_ARG_TYPE('flags', 'string', flags); _setFlagsFromString(flags); } diff --git a/lib/zlib.js b/lib/zlib.js index 3660bd1a7d..f2233beb03 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -127,7 +127,8 @@ function zlibBufferSync(engine, buffer) { } else { throw new ERR_INVALID_ARG_TYPE( 'buffer', - ['string', 'Buffer', 'TypedArray', 'DataView', 'ArrayBuffer'] + ['string', 'Buffer', 'TypedArray', 'DataView', 'ArrayBuffer'], + buffer ); } } diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index e9faa6d9f1..bf02bfcf66 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.js @@ -24,7 +24,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "url" argument must be of type string' + message: 'The "url" argument must be of type string. Received type number' } ); @@ -33,7 +33,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "url" argument must be of type string' + message: 'The "url" argument must be of type string. Received type number' } ); @@ -42,7 +42,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "job" argument must be of type ModuleJob' + message: 'The "job" argument must be of type ModuleJob. ' + + 'Received type string' } ); @@ -51,6 +52,6 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "url" argument must be of type string' + message: 'The "url" argument must be of type string. Received type number' } ); diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 9964c393ed..ac56b409d0 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -317,10 +317,6 @@ try { { // Verify that throws() and doesNotThrow() throw on non-function block. - function typeName(value) { - return value === null ? 'null' : typeof value; - } - const testBlockTypeError = (method, block) => { common.expectsError( () => method(block), @@ -328,7 +324,7 @@ try { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "block" argument must be of type Function. Received ' + - `type ${typeName(block)}` + `type ${typeof block}` } ); }; @@ -369,15 +365,15 @@ assert.throws(() => { { // Bad args to AssertionError constructor should throw TypeError. const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined]; - const re = /^The "options" argument must be of type Object$/; args.forEach((input) => { assert.throws( () => new assert.AssertionError(input), - common.expectsError({ + { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: re - })); + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "options" argument must be of type Object. ' + + `Received type ${typeof input}` + }); }); } diff --git a/test/parallel/test-buffer-compare.js b/test/parallel/test-buffer-compare.js index 9ebd3a970b..e2bd1380d2 100644 --- a/test/parallel/test-buffer-compare.js +++ b/test/parallel/test-buffer-compare.js @@ -28,15 +28,16 @@ assert.strictEqual(Buffer.compare(Buffer.alloc(0), Buffer.alloc(0)), 0); assert.strictEqual(Buffer.compare(Buffer.alloc(0), Buffer.alloc(1)), -1); assert.strictEqual(Buffer.compare(Buffer.alloc(1), Buffer.alloc(0)), 1); -const errMsg = common.expectsError({ +assert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "buf1", "buf2" arguments must be one of ' + - 'type Buffer or Uint8Array' -}, 2); -assert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'), errMsg); - -assert.throws(() => Buffer.compare('abc', Buffer.alloc(1)), errMsg); + message: 'The "buf2" argument must be one of type Buffer or Uint8Array. ' + + 'Received type string' +}); +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' +}); common.expectsError(() => Buffer.alloc(1).compare('abc'), { code: 'ERR_INVALID_ARG_TYPE', diff --git a/test/parallel/test-buffer-concat.js b/test/parallel/test-buffer-concat.js index 9d6c6c7d35..27a485ec9d 100644 --- a/test/parallel/test-buffer-concat.js +++ b/test/parallel/test-buffer-concat.js @@ -44,23 +44,15 @@ assert.notStrictEqual(flatOne, one[0]); assert.strictEqual(flatLong.toString(), check); assert.strictEqual(flatLongLen.toString(), check); -assertWrongList(); -assertWrongList(null); -assertWrongList(Buffer.from('hello')); -assertWrongList([42]); -assertWrongList(['hello', 'world']); -assertWrongList(['hello', Buffer.from('world')]); - -function assertWrongList(value) { - common.expectsError(() => { +[undefined, null, Buffer.from('hello')].forEach((value) => { + assert.throws(() => { Buffer.concat(value); }, { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "list" argument must be one of type ' + - 'Array, Buffer, or Uint8Array' + message: 'The "list" argument must be one of type Array, Buffer, ' + + `or Uint8Array. Received type ${typeof value}` }); -} +}); // eslint-disable-next-line node-core/crypto-check const random10 = common.hasCrypto ? diff --git a/test/parallel/test-child-process-constructor.js b/test/parallel/test-child-process-constructor.js index 33bcdcb669..bf7fffd9c5 100644 --- a/test/parallel/test-child-process-constructor.js +++ b/test/parallel/test-child-process-constructor.js @@ -6,7 +6,7 @@ const { ChildProcess } = require('child_process'); assert.strictEqual(typeof ChildProcess, 'function'); function typeName(value) { - return value === null ? 'null' : typeof value; + return typeof value; } { diff --git a/test/parallel/test-crypto-certificate.js b/test/parallel/test-crypto-certificate.js index 36742154ef..f94c82474e 100644 --- a/test/parallel/test-crypto-certificate.js +++ b/test/parallel/test-crypto-certificate.js @@ -78,39 +78,26 @@ function stripLineEndings(obj) { return obj.replace(/\n/g, ''); } -// direct call Certificate() should return instance +// Direct call Certificate() should return instance assert(Certificate() instanceof Certificate); -[1, {}, [], Infinity, true, 'test', undefined, null].forEach((i) => { - common.expectsError( - () => Certificate.verifySpkac(i), +[1, {}, [], Infinity, true, 'test', undefined, null].forEach((val) => { + assert.throws( + () => Certificate.verifySpkac(val), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, message: 'The "spkac" argument must be one of type Buffer, TypedArray, ' + - 'or DataView' + `or DataView. Received type ${typeof val}` } ); }); -[1, {}, [], Infinity, true, undefined, null].forEach((i) => { - common.expectsError( - () => Certificate.exportPublicKey(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "spkac" argument must be one of type string, Buffer,' + - ' TypedArray, or DataView' - } - ); - - common.expectsError( - () => Certificate.exportChallenge(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "spkac" argument must be one of type string, Buffer,' + - ' TypedArray, or DataView' - } - ); +[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}` + }; + 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 b34f43377c..75ed26c1ff 100644 --- a/test/parallel/test-crypto-cipher-decipher.js +++ b/test/parallel/test-crypto-cipher-decipher.js @@ -81,7 +81,8 @@ testCipher2(Buffer.from('0123456789abcdef')); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "cipher" argument must be of type string' + message: 'The "cipher" argument must be of type string. ' + + 'Received type object' }); common.expectsError( @@ -90,7 +91,7 @@ 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' + 'TypedArray, or DataView. Received type object' }); common.expectsError( @@ -99,7 +100,7 @@ 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' + 'TypedArray, or DataView. Received type object' }); common.expectsError( @@ -108,7 +109,7 @@ testCipher2(Buffer.from('0123456789abcdef')); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "buffer" argument must be one of type Buffer, ' + - 'TypedArray, or DataView' + 'TypedArray, or DataView. Received type object' }); common.expectsError( @@ -117,7 +118,7 @@ testCipher2(Buffer.from('0123456789abcdef')); code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "buffer" argument must be one of type Buffer, ' + - 'TypedArray, or DataView' + 'TypedArray, or DataView. Received type object' }); } @@ -132,7 +133,8 @@ testCipher2(Buffer.from('0123456789abcdef')); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "cipher" argument must be of type string' + message: 'The "cipher" argument must be of type string. ' + + 'Received type object' }); common.expectsError( @@ -141,7 +143,7 @@ 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' + 'TypedArray, or DataView. Received type object' }); } diff --git a/test/parallel/test-crypto-cipheriv-decipheriv.js b/test/parallel/test-crypto-cipheriv-decipheriv.js index dcdec728f1..c0073abcfd 100644 --- a/test/parallel/test-crypto-cipheriv-decipheriv.js +++ b/test/parallel/test-crypto-cipheriv-decipheriv.js @@ -92,7 +92,8 @@ function testCipher3(key, iv) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "cipher" argument must be of type string' + message: 'The "cipher" argument must be of type string. ' + + 'Received type object' }); common.expectsError( @@ -101,7 +102,7 @@ function testCipher3(key, iv) { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "key" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView' + 'TypedArray, or DataView. Received type object' }); common.expectsError( @@ -110,7 +111,7 @@ 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' + 'TypedArray, or DataView. Received type number' }); } @@ -128,7 +129,8 @@ function testCipher3(key, iv) { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "cipher" argument must be of type string' + message: 'The "cipher" argument must be of type string. ' + + 'Received type object' }); common.expectsError( @@ -137,7 +139,7 @@ function testCipher3(key, iv) { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "key" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView' + 'TypedArray, or DataView. Received type object' }); common.expectsError( @@ -146,7 +148,7 @@ 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' + 'TypedArray, or DataView. Received type number' }); } diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index 6b2b8faa36..8e584100d9 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -49,14 +49,14 @@ assert.strictEqual(dh2.verifyError, 0); () => { }, /abc/, {} -].forEach((i) => { +].forEach((input) => { common.expectsError( - () => crypto.createDiffieHellman(i), + () => crypto.createDiffieHellman(input), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "sizeOrKey" argument must be one of type number, string, ' + - 'Buffer, TypedArray, or DataView' + `Buffer, TypedArray, or DataView. Received type ${typeof input}` } ); }); @@ -380,5 +380,6 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "curve" argument must be of type string' + message: 'The "curve" argument must be of type string. ' + + 'Received type undefined' }); diff --git a/test/parallel/test-crypto-engine.js b/test/parallel/test-crypto-engine.js index 43f8b8084c..ca76672de8 100644 --- a/test/parallel/test-crypto-engine.js +++ b/test/parallel/test-crypto-engine.js @@ -12,7 +12,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "id" argument must be of type string' + message: 'The "id" argument must be of type string. Received type boolean' }); common.expectsError( @@ -20,7 +20,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "flags" argument must be of type number' + message: 'The "flags" argument must be of type number. Received type string' }); common.expectsError( diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index e425e1fe4c..f4f7b0dfe5 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -152,7 +152,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "algorithm" argument must be of type string' + message: 'The "algorithm" argument must be of type string. ' + + 'Received type undefined' } ); diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index 0597891e00..223b5c3c07 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' + message: 'The "hmac" argument must be of type string. Received type object' }); common.expectsError( @@ -27,7 +27,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "key" argument must be one of type string, TypedArray, or ' + - 'DataView' + 'DataView. Received type object' }); { diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js index c72551016d..d3f02cf8bd 100644 --- a/test/parallel/test-crypto-pbkdf2.js +++ b/test/parallel/test-crypto-pbkdf2.js @@ -82,7 +82,8 @@ common.expectsError( }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "keylen" argument must be of type number' + message: 'The "keylen" argument must be of type number. ' + + `Received type ${typeof notNumber}` }); }); @@ -107,7 +108,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "digest" argument must be one of type string or null' + message: 'The "digest" argument must be one of type string or null. ' + + 'Received type undefined' }); common.expectsError( @@ -115,58 +117,57 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "digest" argument must be one of type string or null' + message: 'The "digest" argument must be one of type string or null. ' + + 'Received type undefined' }); -[1, {}, [], true, undefined, null].forEach((i) => { +[1, {}, [], true, undefined, null].forEach((input) => { + const msgPart2 = `Buffer, or TypedArray. Received type ${typeof input}`; common.expectsError( - () => crypto.pbkdf2(i, 'salt', 8, 8, 'sha256', common.mustNotCall()), + () => crypto.pbkdf2(input, 'salt', 8, 8, 'sha256', common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "password" argument must be one of type string, ' + - 'Buffer, or TypedArray' + message: `The "password" argument must be one of type string, ${msgPart2}` } ); common.expectsError( - () => crypto.pbkdf2('pass', i, 8, 8, 'sha256', common.mustNotCall()), + () => crypto.pbkdf2('pass', input, 8, 8, 'sha256', common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "salt" argument must be one of type string, ' + - 'Buffer, or TypedArray' + message: `The "salt" argument must be one of type string, ${msgPart2}` } ); common.expectsError( - () => crypto.pbkdf2Sync(i, 'salt', 8, 8, 'sha256'), + () => crypto.pbkdf2Sync(input, 'salt', 8, 8, 'sha256'), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "password" argument must be one of type string, ' + - 'Buffer, or TypedArray' + message: `The "password" argument must be one of type string, ${msgPart2}` } ); common.expectsError( - () => crypto.pbkdf2Sync('pass', i, 8, 8, 'sha256'), + () => crypto.pbkdf2Sync('pass', input, 8, 8, 'sha256'), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "salt" argument must be one of type string, ' + - 'Buffer, or TypedArray' + message: `The "salt" argument must be one of type string, ${msgPart2}` } ); }); ['test', {}, [], true, undefined, null].forEach((i) => { + const received = `Received type ${typeof i}`; common.expectsError( () => crypto.pbkdf2('pass', 'salt', i, 8, 'sha256', common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "iterations" argument must be of type number' + message: `The "iterations" argument must be of type number. ${received}` } ); @@ -175,7 +176,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "iterations" argument must be of type number' + message: `The "iterations" argument must be of type number. ${received}` } ); }); diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index 7619d91191..11cbdbc210 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -315,105 +315,51 @@ common.expectsError( })); } -[1, [], {}, undefined, null, true, Infinity].forEach((i) => { - common.expectsError( - () => crypto.createSign(), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "algorithm" argument must be of type string' - } - ); - common.expectsError( - () => crypto.createVerify(), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "algorithm" argument must be of type string' - } - ); -}); - { const sign = crypto.createSign('SHA1'); const verify = crypto.createVerify('SHA1'); - [1, [], {}, undefined, null, true, Infinity].forEach((i) => { - common.expectsError( - () => sign.update(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "data" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView' - } - ); - common.expectsError( - () => verify.update(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "data" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView' - } - ); - common.expectsError( - () => sign._write(i, 'utf8', () => {}), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "data" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView' - } - ); - common.expectsError( - () => verify._write(i, 'utf8', () => {}), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "data" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView' - } - ); + [1, [], {}, undefined, null, true, Infinity].forEach((input) => { + const type = typeof input; + const errObj = { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "algorithm" argument must be of type string. ' + + `Received type ${type}` + }; + 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}`; + assert.throws(() => sign.update(input), errObj); + assert.throws(() => verify.update(input), errObj); + assert.throws(() => sign._write(input, 'utf8', () => {}), errObj); + assert.throws(() => verify._write(input, 'utf8', () => {}), errObj); }); [ Uint8Array, Uint16Array, Uint32Array, Float32Array, Float64Array - ].forEach((i) => { + ].forEach((clazz) => { // These should all just work - sign.update(new i()); - verify.update(new i()); + sign.update(new clazz()); + verify.update(new clazz()); }); - [1, {}, [], Infinity].forEach((i) => { - common.expectsError( - () => sign.sign(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "key" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView' - } - ); - - common.expectsError( - () => verify.verify(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "key" argument must be one of type string, Buffer, ' + - 'TypedArray, or DataView' - } - ); - - common.expectsError( - () => verify.verify('test', i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "signature" argument must be one of type string, ' + - 'Buffer, TypedArray, or DataView' - } - ); + [1, {}, [], Infinity].forEach((input) => { + const type = typeof input; + const errObj = { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "key" argument must be one of type string, Buffer, ' + + `TypedArray, or DataView. Received type ${type}` + }; + + 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}`; + assert.throws(() => verify.verify('test', input), errObj); }); } diff --git a/test/parallel/test-dgram-custom-lookup.js b/test/parallel/test-dgram-custom-lookup.js index df715f81d6..ae62328364 100644 --- a/test/parallel/test-dgram-custom-lookup.js +++ b/test/parallel/test-dgram-custom-lookup.js @@ -40,7 +40,8 @@ const dns = require('dns'); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "lookup" argument must be of type Function' + message: 'The "lookup" argument must be of type Function. ' + + `Received type ${typeof value}` }); }); } diff --git a/test/parallel/test-dgram-send-address-types.js b/test/parallel/test-dgram-send-address-types.js index b3f4f3fcea..0d208cfdc8 100644 --- a/test/parallel/test-dgram-send-address-types.js +++ b/test/parallel/test-dgram-send-address-types.js @@ -10,47 +10,27 @@ const onMessage = common.mustCall((err, bytes) => { assert.strictEqual(bytes, buf.length); }, 6); -const expectedError = { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: - /^The "address" argument must be one of type string or falsy$/ -}; - const client = dgram.createSocket('udp4').bind(0, () => { const port = client.address().port; - // valid address: false - client.send(buf, port, false, onMessage); - - // valid address: empty string - client.send(buf, port, '', onMessage); - - // valid address: null - client.send(buf, port, null, onMessage); - - // valid address: 0 - client.send(buf, port, 0, onMessage); + // Check valid addresses + [false, '', null, 0, undefined].forEach((address) => { + client.send(buf, port, address, onMessage); + }); - // valid address: undefined - client.send(buf, port, undefined, onMessage); - - // valid address: not provided + // Valid address: not provided client.send(buf, port, onMessage); - // invalid address: object - common.expectsError(() => { - client.send(buf, port, []); - }, expectedError); - - // invalid address: nonzero number - common.expectsError(() => { - client.send(buf, port, 1); - }, expectedError); - - // invalid address: true - common.expectsError(() => { - client.send(buf, port, true); - }, expectedError); + // Check invalid addresses + [[], 1, true].forEach((invalidInput) => { + const expectedError = { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "address" argument must be one of type string or falsy. ' + + `Received type ${typeof invalidInput}` + }; + assert.throws(() => client.send(buf, port, invalidInput), expectedError); + }); }); client.unref(); diff --git a/test/parallel/test-dgram-sendto.js b/test/parallel/test-dgram-sendto.js index 782b2f692b..3922ccbb64 100644 --- a/test/parallel/test-dgram-sendto.js +++ b/test/parallel/test-dgram-sendto.js @@ -1,47 +1,37 @@ 'use strict'; -const common = require('../common'); +require('../common'); +const assert = require('assert'); const dgram = require('dgram'); const socket = dgram.createSocket('udp4'); -const errorMessageOffset = - /^The "offset" argument must be of type number$/; - -common.expectsError(() => { - socket.sendto(); -}, { +const errObj = { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: errorMessageOffset -}); + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "offset" argument must be of type number. Received type ' + + 'undefined' +}; +assert.throws(() => socket.sendto(), errObj); -common.expectsError(() => { - socket.sendto('buffer', 1, 'offset', 'port', 'address', 'cb'); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: /^The "length" argument must be of type number$/ -}); +errObj.message = 'The "length" argument must be of type number. Received ' + + 'type string'; +assert.throws( + () => socket.sendto('buffer', 1, 'offset', 'port', 'address', 'cb'), + errObj); -common.expectsError(() => { - socket.sendto('buffer', 'offset', 1, 'port', 'address', 'cb'); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: errorMessageOffset -}); +errObj.message = 'The "offset" argument must be of type number. Received ' + + 'type string'; +assert.throws( + () => socket.sendto('buffer', 'offset', 1, 'port', 'address', 'cb'), + errObj); -common.expectsError(() => { - socket.sendto('buffer', 1, 1, 10, false, 'cb'); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: /^The "address" argument must be of type string$/ -}); +errObj.message = 'The "address" argument must be of type string. Received ' + + 'type boolean'; +assert.throws( + () => socket.sendto('buffer', 1, 1, 10, false, 'cb'), + errObj); -common.expectsError(() => { - socket.sendto('buffer', 1, 1, false, 'address', 'cb'); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: /^The "port" argument must be of type number$/ -}); +errObj.message = 'The "port" argument must be of type number. Received ' + + 'type boolean'; +assert.throws( + () => socket.sendto('buffer', 1, 1, false, 'address', 'cb'), + errObj); diff --git a/test/parallel/test-event-emitter-add-listeners.js b/test/parallel/test-event-emitter-add-listeners.js index 448db80516..45bfd3832c 100644 --- a/test/parallel/test-event-emitter-add-listeners.js +++ b/test/parallel/test-event-emitter-add-listeners.js @@ -92,5 +92,6 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "listener" argument must be of type Function' + message: 'The "listener" argument must be of type Function. ' + + 'Received type object' }); diff --git a/test/parallel/test-event-emitter-once.js b/test/parallel/test-event-emitter-once.js index fa99a1362a..1bdf0cbf12 100644 --- a/test/parallel/test-event-emitter-once.js +++ b/test/parallel/test-event-emitter-once.js @@ -52,12 +52,12 @@ e.emit('e'); // Verify that the listener must be a function common.expectsError(() => { const ee = new EventEmitter(); - ee.once('foo', null); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "listener" argument must be of type Function' + message: 'The "listener" argument must be of type Function. ' + + 'Received type object' }); { diff --git a/test/parallel/test-event-emitter-prepend.js b/test/parallel/test-event-emitter-prepend.js index dd9a9bdfc5..3259ea47f9 100644 --- a/test/parallel/test-event-emitter-prepend.js +++ b/test/parallel/test-event-emitter-prepend.js @@ -21,12 +21,12 @@ myEE.emit('foo'); // Verify that the listener must be a function common.expectsError(() => { const ee = new EventEmitter(); - ee.prependOnceListener('foo', null); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "listener" argument must be of type Function' + message: 'The "listener" argument must be of type Function. ' + + 'Received type object' }); // 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 75a4c87650..925f828f93 100644 --- a/test/parallel/test-event-emitter-remove-listeners.js +++ b/test/parallel/test-event-emitter-remove-listeners.js @@ -146,12 +146,12 @@ function listener2() {} // Verify that the removed listener must be a function common.expectsError(() => { const ee = new EventEmitter(); - ee.removeListener('foo', null); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "listener" argument must be of type Function' + message: 'The "listener" argument must be of type Function. ' + + 'Received type object' }); { diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index 81070286eb..054068def1 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -97,7 +97,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "path" argument must be one of type string, Buffer, or URL' + message: 'The "path" argument must be one of type string, Buffer, or URL.' + + ' Received type number' } ); diff --git a/test/parallel/test-fs-buffer.js b/test/parallel/test-fs-buffer.js index c4ab80a429..1e898d3891 100644 --- a/test/parallel/test-fs-buffer.js +++ b/test/parallel/test-fs-buffer.js @@ -25,7 +25,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "path" argument must be one of type string, Buffer, or URL' + message: 'The "path" argument must be one of type string, Buffer, or URL.' + + ' Received type boolean' } ); diff --git a/test/parallel/test-fs-chmod.js b/test/parallel/test-fs-chmod.js index 7c1b14ff24..a167fa49ba 100644 --- a/test/parallel/test-fs-chmod.js +++ b/test/parallel/test-fs-chmod.js @@ -146,40 +146,25 @@ if (fs.lchmod) { })); } -['', false, null, undefined, {}, []].forEach((i) => { - common.expectsError( - () => fs.fchmod(i, 0o000), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "fd" argument must be of type integer' - } - ); - common.expectsError( - () => fs.fchmodSync(i, 0o000), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "fd" argument must be of type integer' - } - ); +['', false, null, undefined, {}, []].forEach((input) => { + const errObj = { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "fd" argument must be of type integer' + }; + assert.throws(() => fs.fchmod(input, 0o000), errObj); + assert.throws(() => fs.fchmodSync(input, 0o000), errObj); }); -[false, 1, {}, [], null, undefined].forEach((i) => { - common.expectsError( - () => fs.chmod(i, 1, common.mustNotCall()), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError - } - ); - common.expectsError( - () => fs.chmodSync(i, 1), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError - } - ); +[false, 1, {}, [], null, undefined].forEach((input) => { + const errObj = { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "path" argument must be one of type string, Buffer, or URL.' + + ` Received type ${typeof input}` + }; + assert.throws(() => fs.chmod(input, 1, common.mustNotCall()), errObj); + assert.throws(() => fs.chmodSync(input, 1), errObj); }); process.on('exit', function() { diff --git a/test/parallel/test-fs-close-errors.js b/test/parallel/test-fs-close-errors.js index f81d96c056..3be8b4ce33 100644 --- a/test/parallel/test-fs-close-errors.js +++ b/test/parallel/test-fs-close-errors.js @@ -3,24 +3,16 @@ // This tests that the errors thrown from fs.close and fs.closeSync // include the desired properties -const common = require('../common'); +require('../common'); +const assert = require('assert'); const fs = require('fs'); -['', false, null, undefined, {}, []].forEach((i) => { - common.expectsError( - () => fs.close(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "fd" argument must be of type integer' - } - ); - common.expectsError( - () => fs.closeSync(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "fd" argument must be of type integer' - } - ); +['', false, null, undefined, {}, []].forEach((input) => { + const errObj = { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "fd" argument must be of type integer' + }; + assert.throws(() => fs.close(input), errObj); + assert.throws(() => fs.closeSync(input), errObj); }); diff --git a/test/parallel/test-fs-read-type.js b/test/parallel/test-fs-read-type.js index 3338410bec..b47a7be177 100644 --- a/test/parallel/test-fs-read-type.js +++ b/test/parallel/test-fs-read-type.js @@ -14,7 +14,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "buffer" argument must be one of type Buffer or Uint8Array' + message: 'The "buffer" argument must be one of type Buffer or Uint8Array.' + + ' Received type number' } ); @@ -26,8 +27,11 @@ common.expectsError( expected.length, 0, common.mustNotCall()); - }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "fd" argument must be of type integer' }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "fd" argument must be of type integer' + }); }); common.expectsError(() => { @@ -56,7 +60,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "buffer" argument must be one of type Buffer or Uint8Array' + message: 'The "buffer" argument must be one of type Buffer or Uint8Array.' + + ' Received type number' } ); @@ -67,8 +72,11 @@ common.expectsError( 0, expected.length, 0); - }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "fd" argument must be of type integer' }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "fd" argument must be of type integer' + }); }); common.expectsError(() => { diff --git a/test/parallel/test-fs-readfile-error.js b/test/parallel/test-fs-readfile-error.js index 97633c9a88..fe6174c577 100644 --- a/test/parallel/test-fs-readfile-error.js +++ b/test/parallel/test-fs-readfile-error.js @@ -60,7 +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', + message: 'The "path" argument must be one of type string, Buffer, or URL.' + + ' Received type function', type: TypeError } ); diff --git a/test/parallel/test-fs-rename-type-check.js b/test/parallel/test-fs-rename-type-check.js index 68126e9f7e..b8f0549f0c 100644 --- a/test/parallel/test-fs-rename-type-check.js +++ b/test/parallel/test-fs-rename-type-check.js @@ -1,43 +1,41 @@ 'use strict'; const common = require('../common'); +const assert = require('assert'); const fs = require('fs'); -[false, 1, [], {}, null, undefined].forEach((i) => { - common.expectsError( - () => fs.rename(i, 'does-not-exist', common.mustNotCall()), +[false, 1, [], {}, null, undefined].forEach((input) => { + const type = `of type string, Buffer, or URL. Received type ${typeof input}`; + assert.throws( + () => fs.rename(input, 'does-not-exist', common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: - 'The "oldPath" argument must be one of type string, Buffer, or URL' + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: `The "oldPath" argument must be one ${type}` } ); - common.expectsError( - () => fs.rename('does-not-exist', i, common.mustNotCall()), + assert.throws( + () => fs.rename('does-not-exist', input, common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: - 'The "newPath" argument must be one of type string, Buffer, or URL' + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: `The "newPath" argument must be one ${type}` } ); - common.expectsError( - () => fs.renameSync(i, 'does-not-exist'), + assert.throws( + () => fs.renameSync(input, 'does-not-exist'), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: - 'The "oldPath" argument must be one of type string, Buffer, or URL' + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: `The "oldPath" argument must be one ${type}` } ); - common.expectsError( - () => fs.renameSync('does-not-exist', i), + assert.throws( + () => fs.renameSync('does-not-exist', input), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: - 'The "newPath" argument must be one of type string, Buffer, or URL' + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: `The "newPath" argument must be one ${type}` } ); }); diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index 7f0f535d0c..bbb3281187 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -131,52 +131,46 @@ fs.stat(__filename, common.mustCall(function(err, s) { }); })); -['', false, null, undefined, {}, []].forEach((i) => { - common.expectsError( - () => fs.fstat(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "fd" argument must be of type integer' - } - ); - common.expectsError( - () => fs.fstatSync(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "fd" argument must be of type integer' - } - ); +['', false, null, undefined, {}, []].forEach((input) => { + ['fstat', 'fstatSync'].forEach((fnName) => { + assert.throws( + () => fs[fnName](input), + { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "fd" argument must be of type integer' + } + ); + }); }); -[false, 1, {}, [], null, undefined].forEach((i) => { - common.expectsError( - () => fs.lstat(i, common.mustNotCall()), +[false, 1, {}, [], null, undefined].forEach((input) => { + assert.throws( + () => fs.lstat(input, common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError + name: 'TypeError [ERR_INVALID_ARG_TYPE]' } ); - common.expectsError( - () => fs.lstatSync(i), + assert.throws( + () => fs.lstatSync(input), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError + name: 'TypeError [ERR_INVALID_ARG_TYPE]' } ); - common.expectsError( - () => fs.stat(i, common.mustNotCall()), + assert.throws( + () => fs.stat(input, common.mustNotCall()), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError + name: 'TypeError [ERR_INVALID_ARG_TYPE]' } ); - common.expectsError( - () => fs.statSync(i), + assert.throws( + () => fs.statSync(input), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError + name: 'TypeError [ERR_INVALID_ARG_TYPE]' } ); }); diff --git a/test/parallel/test-fs-truncate.js b/test/parallel/test-fs-truncate.js index 28a9852d82..e0d69defe7 100644 --- a/test/parallel/test-fs-truncate.js +++ b/test/parallel/test-fs-truncate.js @@ -182,12 +182,12 @@ function testFtruncate(cb) { const fd = fs.openSync(file5, 'r+'); process.on('exit', () => fs.closeSync(fd)); - ['', false, null, {}, []].forEach((i) => { - common.expectsError( - () => fs.ftruncate(fd, i), + ['', false, null, {}, []].forEach((input) => { + assert.throws( + () => fs.ftruncate(fd, input), { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, + name: 'TypeError [ERR_INVALID_ARG_TYPE]', message: 'The "len" argument must be of type integer' } ); @@ -210,21 +210,15 @@ function testFtruncate(cb) { })); } -['', false, null, undefined, {}, []].forEach((i) => { - common.expectsError( - () => fs.ftruncate(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "fd" argument must be of type integer' - } - ); - common.expectsError( - () => fs.ftruncateSync(i), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "fd" argument must be of type integer' - } - ); +['', false, null, undefined, {}, []].forEach((input) => { + ['ftruncate', 'ftruncateSync'].forEach((fnName) => { + assert.throws( + () => fs[fnName](input), + { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "fd" argument must be of type integer' + } + ); + }); }); diff --git a/test/parallel/test-fs-watch.js b/test/parallel/test-fs-watch.js index 24600b79ce..a6a14465e2 100644 --- a/test/parallel/test-fs-watch.js +++ b/test/parallel/test-fs-watch.js @@ -79,14 +79,14 @@ for (const testCase of cases) { }, 100); } -[false, 1, {}, [], null, undefined].forEach((i) => { +[false, 1, {}, [], null, undefined].forEach((input) => { common.expectsError( - () => fs.watch(i, common.mustNotCall()), + () => 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' + message: 'The "filename" argument must be one of type string, Buffer, ' + + `or URL. Received type ${typeof input}` } ); }); diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js index 2473a08eb1..0ff05f234c 100644 --- a/test/parallel/test-http-mutable-headers.js +++ b/test/parallel/test-http-mutable-headers.js @@ -71,7 +71,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' + message: 'The "name" argument must be of type string. ' + + 'Received type undefined' } ); common.expectsError( @@ -79,7 +80,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' + message: 'The "name" argument must be of type string. ' + + 'Received type undefined' } ); @@ -122,7 +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' + message: 'The "name" argument must be of type string. ' + + `Received type ${typeof val}` } ); }); diff --git a/test/parallel/test-http-outgoing-proto.js b/test/parallel/test-http-outgoing-proto.js index f223bc5b9d..0070f53994 100644 --- a/test/parallel/test-http-outgoing-proto.js +++ b/test/parallel/test-http-outgoing-proto.js @@ -79,7 +79,8 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The first argument must be one of type string or Buffer' + message: 'The first argument must be one of type string or Buffer. ' + + 'Received type undefined' }); common.expectsError(() => { @@ -88,7 +89,8 @@ common.expectsError(() => { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The first argument must be one of type string or Buffer' + message: 'The first argument must be one of type string or Buffer. ' + + 'Received type number' }); // addTrailers() diff --git a/test/parallel/test-http2-client-setNextStreamID-errors.js b/test/parallel/test-http2-client-setNextStreamID-errors.js index 0c982061b8..3fb4728b7d 100644 --- a/test/parallel/test-http2-client-setNextStreamID-errors.js +++ b/test/parallel/test-http2-client-setNextStreamID-errors.js @@ -48,7 +48,8 @@ server.listen(0, common.mustCall(() => { { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "id" argument must be of type number' + message: 'The "id" argument must be of type number. Received type ' + + typeof value } ); }); diff --git a/test/parallel/test-http2-compat-serverrequest-headers.js b/test/parallel/test-http2-compat-serverrequest-headers.js index 5843104c01..f445dc46d8 100644 --- a/test/parallel/test-http2-compat-serverrequest-headers.js +++ b/test/parallel/test-http2-compat-serverrequest-headers.js @@ -53,11 +53,11 @@ server.listen(0, common.mustCall(function() { message: 'The "method" argument must be of type string' } ); - common.expectsError( + assert.throws( () => request.method = true, { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, + name: 'TypeError [ERR_INVALID_ARG_TYPE]', message: 'The "method" argument must be of type string' } ); diff --git a/test/parallel/test-http2-compat-serverresponse-headers.js b/test/parallel/test-http2-compat-serverresponse-headers.js index 7b5313b8e7..8c8c4867dd 100644 --- a/test/parallel/test-http2-compat-serverresponse-headers.js +++ b/test/parallel/test-http2-compat-serverresponse-headers.js @@ -41,30 +41,17 @@ server.listen(0, common.mustCall(function() { response.removeHeader(denormalised); assert.strictEqual(response.hasHeader(denormalised), false); - common.expectsError( - () => response.hasHeader(), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "name" argument must be of type string' - } - ); - common.expectsError( - () => response.getHeader(), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "name" argument must be of type string' - } - ); - common.expectsError( - () => response.removeHeader(), - { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "name" argument must be of type string' - } - ); + ['hasHeader', 'getHeader', 'removeHeader'].forEach((fnName) => { + assert.throws( + () => response[fnName](), + { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "name" argument must be of type string. Received ' + + 'type undefined' + } + ); + }); [ ':status', @@ -95,11 +82,12 @@ server.listen(0, common.mustCall(function() { message: 'Invalid value "undefined" for header "foo-bar"' }); common.expectsError( - () => response.setHeader(), // header name undefined + () => response.setHeader(), // Header name undefined { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "name" argument must be of type string' + message: 'The "name" argument must be of type string. Received type ' + + 'undefined' } ); common.expectsError( diff --git a/test/parallel/test-http2-compat-serverresponse-trailers.js b/test/parallel/test-http2-compat-serverresponse-trailers.js index 66ad8843fa..fe722c84ee 100644 --- a/test/parallel/test-http2-compat-serverresponse-trailers.js +++ b/test/parallel/test-http2-compat-serverresponse-trailers.js @@ -40,11 +40,12 @@ server.listen(0, common.mustCall(() => { } ); common.expectsError( - () => response.setTrailer(), // trailer name undefined + () => response.setTrailer(), // Trailer name undefined { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "name" argument must be of type string' + message: 'The "name" argument must be of type string. Received type ' + + 'undefined' } ); common.expectsError( diff --git a/test/parallel/test-http2-createsecureserver-nooptions.js b/test/parallel/test-http2-createsecureserver-nooptions.js index 71764f5783..767797febc 100644 --- a/test/parallel/test-http2-createsecureserver-nooptions.js +++ b/test/parallel/test-http2-createsecureserver-nooptions.js @@ -4,19 +4,19 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +const assert = require('assert'); const http2 = require('http2'); -const invalidOptions = [() => {}, 1, 'test', null]; -const invalidArgTypeError = { - type: TypeError, - code: 'ERR_INVALID_ARG_TYPE', - message: 'The "options" argument must be of type Object' -}; - // Error if options are not passed to createSecureServer +const invalidOptions = [() => {}, 1, 'test', null]; invalidOptions.forEach((invalidOption) => { - common.expectsError( + assert.throws( () => http2.createSecureServer(invalidOption), - invalidArgTypeError + { + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "options" argument must be of type Object. Received ' + + `type ${typeof invalidOption}` + } ); }); diff --git a/test/parallel/test-http2-getpackedsettings.js b/test/parallel/test-http2-getpackedsettings.js index 56b9632113..77c8cf442f 100644 --- a/test/parallel/test-http2-getpackedsettings.js +++ b/test/parallel/test-http2-getpackedsettings.js @@ -99,14 +99,15 @@ http2.getPackedSettings({ enablePush: false }); 0x00, 0x00, 0x00, 0x64, 0x00, 0x06, 0x00, 0x00, 0x00, 0x64, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01]); - [1, true, '', [], {}, NaN].forEach((i) => { + [1, true, '', [], {}, NaN].forEach((input) => { common.expectsError(() => { - http2.getUnpackedSettings(i); + http2.getUnpackedSettings(input); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "buf" argument must be one of type Buffer, TypedArray, or DataView' + 'The "buf" argument must be one of type Buffer, TypedArray, or ' + + `DataView. Received type ${typeof input}` }); }); diff --git a/test/parallel/test-http2-invalidargtypes-errors.js b/test/parallel/test-http2-invalidargtypes-errors.js index ff189a2977..d7c451569e 100644 --- a/test/parallel/test-http2-invalidargtypes-errors.js +++ b/test/parallel/test-http2-invalidargtypes-errors.js @@ -13,7 +13,8 @@ server.on('stream', common.mustCall((stream) => { { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "code" argument must be of type number' + message: 'The "code" argument must be of type number. ' + + 'Received type string' } ); stream.respond(); diff --git a/test/parallel/test-http2-misc-util.js b/test/parallel/test-http2-misc-util.js index 993424f771..14dc4a5366 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 of type Object' + message: 'The "test" argument must be of type Object. Received type string' }); common.expectsError( @@ -43,7 +43,7 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "test" argument must be of type Date' + message: 'The "test" argument must be of type Date. Received type string' }); assertIsObject({}, 'test'); diff --git a/test/parallel/test-http2-ping.js b/test/parallel/test-http2-ping.js index 0280f656d0..87c8c29d1b 100644 --- a/test/parallel/test-http2-ping.js +++ b/test/parallel/test-http2-ping.js @@ -81,14 +81,14 @@ server.listen(0, common.mustCall(() => { // should throw if payload is not of type ArrayBufferView { - [1, true, {}, []].forEach((invalidPayload) => + [1, true, {}, []].forEach((payload) => common.expectsError( - () => client.ping(invalidPayload), + () => client.ping(payload), { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "payload" argument must be one of type' + - ' Buffer, TypedArray, or DataView' + message: 'The "payload" argument must be one of type Buffer, ' + + `TypedArray, or DataView. Received type ${typeof payload}` } ) ); diff --git a/test/parallel/test-http2-respond-file-fd-errors.js b/test/parallel/test-http2-respond-file-fd-errors.js index 44876b60e1..5532e81855 100644 --- a/test/parallel/test-http2-respond-file-fd-errors.js +++ b/test/parallel/test-http2-respond-file-fd-errors.js @@ -43,7 +43,8 @@ server.on('stream', common.mustCall((stream) => { { type: TypeError, code: 'ERR_INVALID_ARG_TYPE', - message: 'The "fd" argument must be of type number' + message: 'The "fd" argument must be of type number. Received type ' + + typeof 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 6cee8f2572..95849411a2 100644 --- a/test/parallel/test-http2-server-shutdown-options-errors.js +++ b/test/parallel/test-http2-server-shutdown-options-errors.js @@ -18,30 +18,32 @@ const types = [ server.on('stream', common.mustCall((stream) => { const session = stream.session; - types.forEach((i) => { + types.forEach((input) => { common.expectsError( - () => session.goaway(i), + () => session.goaway(input), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "code" argument must be of type number' + message: 'The "code" argument must be of type number. Received type ' + + typeof input } ); common.expectsError( - () => session.goaway(0, i), + () => session.goaway(0, input), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "lastStreamID" argument must be of type number' + message: 'The "lastStreamID" argument must be of type number. ' + + `Received type ${typeof input}` } ); common.expectsError( - () => session.goaway(0, 0, i), + () => session.goaway(0, 0, input), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "opaqueData" argument must be one of type Buffer, ' + - 'TypedArray, or DataView' + `TypedArray, or DataView. Received type ${typeof input}` } ); }); diff --git a/test/parallel/test-http2-util-asserts.js b/test/parallel/test-http2-util-asserts.js index bfed09de4f..3db74e2f2e 100644 --- a/test/parallel/test-http2-util-asserts.js +++ b/test/parallel/test-http2-util-asserts.js @@ -25,11 +25,12 @@ const { Infinity, [], [{}] -].forEach((i) => { - common.expectsError(() => assertIsObject(i, 'foo', 'Object'), +].forEach((input) => { + common.expectsError(() => assertIsObject(input, 'foo', 'Object'), { code: 'ERR_INVALID_ARG_TYPE', - message: /^The "foo" argument must be of type Object$/ + message: 'The "foo" argument must be of type Object. ' + + `Received type ${typeof input}` }); }); diff --git a/test/parallel/test-https-options-boolean-check.js b/test/parallel/test-https-options-boolean-check.js index fa223aa887..cefa9c1d0a 100644 --- a/test/parallel/test-https-options-boolean-check.js +++ b/test/parallel/test-https-options-boolean-check.js @@ -6,6 +6,7 @@ const fixtures = require('../common/fixtures'); if (!common.hasCrypto) common.skip('missing crypto'); +const assert = require('assert'); const https = require('https'); function toArrayBuffer(buf) { @@ -38,8 +39,6 @@ const caArrBuff = toArrayBuffer(caCert); const keyDataView = toDataView(keyBuff); const certDataView = toDataView(certBuff); const caArrDataView = toDataView(caCert); -const invalidKeyRE = /^The "key" argument must be one of type string, Buffer, TypedArray, or DataView$/; -const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, TypedArray, or DataView$/; // Checks to ensure https.createServer doesn't throw an error // Format ['key', 'cert'] @@ -63,50 +62,59 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, [false, [certStr, certStr2]], [[{ pem: keyBuff }], false], [[{ pem: keyBuff }, { pem: keyBuff }], false] -].forEach((params) => { - https.createServer({ - key: params[0], - cert: params[1] - }); +].forEach(([key, cert]) => { + https.createServer({ key, cert }); }); // Checks to ensure https.createServer predictably throws an error // Format ['key', 'cert', 'expected message'] [ - [true, certBuff, invalidKeyRE], - [keyBuff, true, invalidCertRE], - [true, certStr, invalidKeyRE], - [keyStr, true, invalidCertRE], - [true, certArrBuff, invalidKeyRE], - [keyArrBuff, true, invalidCertRE], - [true, certDataView, invalidKeyRE], - [keyDataView, true, invalidCertRE], - [true, true, invalidCertRE], - [true, false, invalidKeyRE], - [false, true, invalidCertRE], - [true, false, invalidKeyRE], - [{ pem: keyBuff }, false, invalidKeyRE], - [false, { pem: keyBuff }, invalidCertRE], - [1, false, invalidKeyRE], - [false, 1, invalidCertRE], - [[keyBuff, true], [certBuff, certBuff2], invalidKeyRE], - [[true, keyStr2], [certStr, certStr2], invalidKeyRE], - [[keyBuff, keyBuff2], [true, certBuff2], invalidCertRE], - [[keyStr, keyStr2], [certStr, true], invalidCertRE], - [[true, false], [certBuff, certBuff2], invalidKeyRE], - [[keyStr, keyStr2], [true, false], invalidCertRE], - [[keyStr, keyStr2], true, invalidCertRE], - [true, [certBuff, certBuff2], invalidKeyRE] -].forEach((params) => { - common.expectsError(() => { - https.createServer({ - key: params[0], - cert: params[1] - }); + [true, certBuff], + [true, certStr], + [true, certArrBuff], + [true, certDataView], + [true, false], + [true, false], + [{ pem: keyBuff }, false, 'pem'], + [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]); + assert.throws(() => { + https.createServer({ key, cert }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "key" argument must be one of type string, Buffer, ' + + `TypedArray, or DataView. Received type ${type}` + }); +}); + +[ + [keyBuff, true], + [keyStr, true], + [keyArrBuff, true], + [keyDataView, true], + [true, true], + [false, true], + [false, { pem: keyBuff }, 'pem'], + [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]); + assert.throws(() => { + https.createServer({ key, cert }); }, { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: params[2] + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "cert" argument must be one of type string, Buffer, ' + + `TypedArray, or DataView. Received type ${type}` }); }); @@ -120,12 +128,8 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, [keyBuff, certBuff, caArrBuff], [keyBuff, certBuff, caArrDataView], [keyBuff, certBuff, false], -].forEach((params) => { - https.createServer({ - key: params[0], - cert: params[1], - ca: params[2] - }); +].forEach(([key, cert, ca]) => { + https.createServer({ key, cert, ca }); }); // Checks to ensure https.createServer throws an error for CA assignment @@ -135,17 +139,15 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, [keyBuff, certBuff, {}], [keyBuff, certBuff, 1], [keyBuff, certBuff, true], - [keyBuff, certBuff, [caCert, true]] -].forEach((params) => { - common.expectsError(() => { - https.createServer({ - key: params[0], - cert: params[1], - ca: params[2] - }); + [keyBuff, certBuff, [caCert, true], 1] +].forEach(([key, cert, ca, index]) => { + const type = typeof (index ? ca[index] : ca); + assert.throws(() => { + https.createServer({ key, cert, ca }); }, { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/ + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "ca" argument must be one of type string, Buffer, ' + + `TypedArray, or DataView. Received type ${type}` }); }); diff --git a/test/parallel/test-icu-transcode.js b/test/parallel/test-icu-transcode.js index 4f51e72304..07a7f07324 100644 --- a/test/parallel/test-icu-transcode.js +++ b/test/parallel/test-icu-transcode.js @@ -47,7 +47,7 @@ common.expectsError( type: TypeError, code: 'ERR_INVALID_ARG_TYPE', message: 'The "source" argument must be one of type Buffer ' + - 'or Uint8Array. Received type null' + 'or Uint8Array. Received type object' } ); diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js index dd6491ebce..7521633c62 100644 --- a/test/parallel/test-internal-errors.js +++ b/test/parallel/test-internal-errors.js @@ -90,36 +90,6 @@ common.expectsError(() => { message: /.+ does not match \S/ }); -// // Test ERR_INVALID_ARG_TYPE -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b']), - 'The "a" argument must be of type b'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', ['b']]), - 'The "a" argument must be of type b'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', ['b', 'c']]), - 'The "a" argument must be one of type b or c'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', - ['a', ['b', 'c', 'd']]), - 'The "a" argument must be one of type b, c, or d'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b', 'c']), - 'The "a" argument must be of type b. Received type string'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', - ['a', 'b', undefined]), - 'The "a" argument must be of type b. Received type ' + - 'undefined'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', - ['a', 'b', null]), - 'The "a" argument must be of type b. Received type null'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', 'not b']), - 'The "a" argument must not be of type b'); -assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a.b', 'not c']), - 'The "a.b" property must not be of type c'); -assert.strictEqual( - errors.message('ERR_INVALID_ARG_TYPE', ['first argument', 'c']), - 'The first argument must be of type c'); -assert.strictEqual( - errors.message('ERR_INVALID_ARG_TYPE', [['a', 'b', 'c'], 'not d']), - 'The "a", "b", "c" arguments must not be of type d'); - // Test ERR_INVALID_FD_TYPE assert.strictEqual(errors.message('ERR_INVALID_FD_TYPE', ['a']), 'Unsupported fd type: a'); diff --git a/test/parallel/test-net-connect-buffer.js b/test/parallel/test-net-connect-buffer.js index 028ea22183..f58820d58e 100644 --- a/test/parallel/test-net-connect-buffer.js +++ b/test/parallel/test-net-connect-buffer.js @@ -62,16 +62,16 @@ tcp.listen(0, common.mustCall(function() { undefined, 1, 1.0, - 1 / 0, +Infinity, -Infinity, [], {} - ].forEach((v) => { - common.expectsError(() => socket.write(v), { + ].forEach((value) => { + common.expectsError(() => socket.write(value), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "chunk" argument must be one of type string or Buffer' + message: 'The "chunk" argument must be one of type string or Buffer. ' + + `Received type ${typeof value}` }); }); diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index 3586ebece1..c50093301f 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -220,10 +220,6 @@ function checkFormat(path, testCases) { assert.strictEqual(path.format(testCase[0]), testCase[1]); }); - function typeName(value) { - return value === null ? 'null' : typeof value; - } - [null, undefined, 1, true, false, 'string'].forEach((pathObject) => { common.expectsError(() => { path.format(pathObject); @@ -231,7 +227,7 @@ function checkFormat(path, testCases) { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "pathObject" argument must be of type Object. ' + - `Received type ${typeName(pathObject)}` + `Received type ${typeof pathObject}` }); }); } diff --git a/test/parallel/test-performance-function.js b/test/parallel/test-performance-function.js index 0deaa0e057..57dd2871ee 100644 --- a/test/parallel/test-performance-function.js +++ b/test/parallel/test-performance-function.js @@ -70,12 +70,13 @@ const { } { - [1, {}, [], null, undefined, Infinity].forEach((i) => { - common.expectsError(() => performance.timerify(i), + [1, {}, [], null, undefined, Infinity].forEach((input) => { + common.expectsError(() => performance.timerify(input), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "fn" argument must be of type Function' + message: 'The "fn" argument must be of type ' + + `Function. Received type ${typeof input}` }); }); } diff --git a/test/parallel/test-performanceobserver.js b/test/parallel/test-performanceobserver.js index 2a62999522..08e07a1518 100644 --- a/test/parallel/test-performanceobserver.js +++ b/test/parallel/test-performanceobserver.js @@ -37,14 +37,14 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0); }); const observer = new PerformanceObserver(common.mustNotCall()); - [1, null, undefined].forEach((i) => { - //observer.observe(i); + [1, null, undefined].forEach((input) => { common.expectsError( - () => observer.observe(i), + () => observer.observe(input), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type Object' + message: 'The "options" argument must be of type Object. ' + + `Received type ${typeof input}` }); }); diff --git a/test/parallel/test-process-exception-capture-errors.js b/test/parallel/test-process-exception-capture-errors.js index 7053497ada..d2f5b86177 100644 --- a/test/parallel/test-process-exception-capture-errors.js +++ b/test/parallel/test-process-exception-capture-errors.js @@ -6,7 +6,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "fn" argument must be one of type Function or null' + message: 'The "fn" argument must be one of type Function or null. ' + + 'Received type number' } ); diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index 594a2a6a0b..e69be183fb 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -38,24 +38,14 @@ const assert = require('assert'); // // process.pid, String(process.pid): ourself -const invalidPidArgument = common.expectsError({ - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "pid" argument must be of type number' -}, 6); - -assert.throws(function() { process.kill('SIGTERM'); }, - invalidPidArgument); -assert.throws(function() { process.kill(null); }, - invalidPidArgument); -assert.throws(function() { process.kill(undefined); }, - invalidPidArgument); -assert.throws(function() { process.kill(+'not a number'); }, - invalidPidArgument); -assert.throws(function() { process.kill(1 / 0); }, - invalidPidArgument); -assert.throws(function() { process.kill(-1 / 0); }, - invalidPidArgument); +['SIGTERM', null, undefined, NaN, Infinity, -Infinity].forEach((val) => { + assert.throws(() => process.kill(val), { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "pid" argument must be of type number. ' + + `Received type ${typeof val}` + }); +}); // Test that kill throws an error for unknown signal names common.expectsError(() => process.kill(0, 'test'), { diff --git a/test/parallel/test-tls-basic-validations.js b/test/parallel/test-tls-basic-validations.js index 501cfd91d0..a2f7c8d461 100644 --- a/test/parallel/test-tls-basic-validations.js +++ b/test/parallel/test-tls-basic-validations.js @@ -26,7 +26,8 @@ common.expectsError(() => tls.createServer({ handshakeTimeout: 'abcd' }), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "timeout" argument must be of type number' + message: 'The "timeout" argument must ' + + 'be of type number' } ); diff --git a/test/parallel/test-tls-error-servername.js b/test/parallel/test-tls-error-servername.js index 8f6d1c5c6d..c42ff2fe73 100644 --- a/test/parallel/test-tls-error-servername.js +++ b/test/parallel/test-tls-error-servername.js @@ -27,7 +27,8 @@ const client = connect({ client.setServername(value); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "name" argument must be of type string' + message: 'The "name" argument must be of type string. ' + + `Received type ${typeof value}` }); }); diff --git a/test/parallel/test-tls-no-cert-required.js b/test/parallel/test-tls-no-cert-required.js index c6ad117831..ef1d366c91 100644 --- a/test/parallel/test-tls-no-cert-required.js +++ b/test/parallel/test-tls-no-cert-required.js @@ -43,7 +43,8 @@ common.expectsError(() => tls.createServer('this is not valid'), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type Object' + message: 'The "options" argument must be of type ' + + 'Object. Received type string' } ); diff --git a/test/parallel/test-tls-options-boolean-check.js b/test/parallel/test-tls-options-boolean-check.js index 53f595e0de..de21da63ff 100644 --- a/test/parallel/test-tls-options-boolean-check.js +++ b/test/parallel/test-tls-options-boolean-check.js @@ -38,8 +38,6 @@ const caArrBuff = toArrayBuffer(caCert); const keyDataView = toDataView(keyBuff); const certDataView = toDataView(certBuff); const caArrDataView = toDataView(caCert); -const invalidKeyRE = /^The "key" argument must be one of type string, Buffer, TypedArray, or DataView$/; -const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, TypedArray, or DataView$/; // Checks to ensure tls.createServer doesn't throw an error // Format ['key', 'cert'] @@ -70,37 +68,51 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, // Checks to ensure tls.createServer predictably throws an error // Format ['key', 'cert', 'expected message'] [ - [true, certBuff, invalidKeyRE], - [keyBuff, true, invalidCertRE], - [true, certStr, invalidKeyRE], - [keyStr, true, invalidCertRE], - [true, certArrBuff, invalidKeyRE], - [keyArrBuff, true, invalidCertRE], - [true, certDataView, invalidKeyRE], - [keyDataView, true, invalidCertRE], - [true, true, invalidCertRE], - [true, false, invalidKeyRE], - [false, true, invalidCertRE], - [true, false, invalidKeyRE], - [{ pem: keyBuff }, false, invalidKeyRE], - [false, { pem: keyBuff }, invalidCertRE], - [1, false, invalidKeyRE], - [false, 1, invalidCertRE], - [[keyBuff, true], [certBuff, certBuff2], invalidKeyRE], - [[true, keyStr2], [certStr, certStr2], invalidKeyRE], - [[keyBuff, keyBuff2], [true, certBuff2], invalidCertRE], - [[keyStr, keyStr2], [certStr, true], invalidCertRE], - [[true, false], [certBuff, certBuff2], invalidKeyRE], - [[keyStr, keyStr2], [true, false], invalidCertRE], - [[keyStr, keyStr2], true, invalidCertRE], - [true, [certBuff, certBuff2], invalidKeyRE] -].forEach(([key, cert, message]) => { + [true, certBuff], + [true, certStr], + [true, certArrBuff], + [true, certDataView], + [true, false], + [true, false], + [{ pem: keyBuff }, false, 'pem'], + [[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]); common.expectsError(() => { tls.createServer({ key, cert }); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message + message: 'The "key" argument must be one of type string, Buffer, ' + + `TypedArray, or DataView. Received type ${type}` + }); +}); + +[ + [keyBuff, true], + [keyStr, true], + [keyArrBuff, true], + [keyDataView, true], + [true, true], + [false, true], + [false, { pem: keyBuff }, 'pem'], + [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]); + common.expectsError(() => { + tls.createServer({ key, cert }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "cert" argument must be one of type string, Buffer, ' + + `TypedArray, or DataView. Received type ${type}` }); }); @@ -125,32 +137,16 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, [keyBuff, certBuff, {}], [keyBuff, certBuff, 1], [keyBuff, certBuff, true], - [keyBuff, certBuff, [caCert, true]] -].forEach(([key, cert, ca]) => { - common.expectsError(() => { - tls.createServer({ key, cert, ca }); - }, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/ - }); -}); - -// Checks to ensure tls.createServer throws an error for CA assignment -// Format ['key', 'cert', 'ca'] -[ - [keyBuff, certBuff, true], - [keyBuff, certBuff, {}], - [keyBuff, certBuff, 1], - [keyBuff, certBuff, true], - [keyBuff, certBuff, [caCert, true]] -].forEach(([key, cert, ca]) => { + [keyBuff, certBuff, [caCert, true], 1] +].forEach(([key, cert, ca, index]) => { + const type = typeof (index === undefined ? ca : ca[index]); common.expectsError(() => { tls.createServer({ key, cert, ca }); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/ + message: 'The "ca" argument must be one of type string, Buffer, ' + + `TypedArray, or DataView. Received type ${type}` }); }); diff --git a/test/parallel/test-url-format-invalid-input.js b/test/parallel/test-url-format-invalid-input.js index 4f0f1a11d7..1a0df32657 100644 --- a/test/parallel/test-url-format-invalid-input.js +++ b/test/parallel/test-url-format-invalid-input.js @@ -5,7 +5,7 @@ const url = require('url'); const throwsObjsAndReportTypes = new Map([ [undefined, 'undefined'], - [null, 'null'], + [null, 'object'], [true, 'boolean'], [false, 'boolean'], [0, 'number'], diff --git a/test/parallel/test-url-format-whatwg.js b/test/parallel/test-url-format-whatwg.js index c26000cb56..26cef6063c 100644 --- a/test/parallel/test-url-format-whatwg.js +++ b/test/parallel/test-url-format-whatwg.js @@ -21,15 +21,17 @@ assert.strictEqual( ); { - const expectedErr = common.expectsError({ - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options" argument must be of type Object' - }, 4); - assert.throws(() => url.format(myURL, true), expectedErr); - assert.throws(() => url.format(myURL, 1), expectedErr); - assert.throws(() => url.format(myURL, 'test'), expectedErr); - assert.throws(() => url.format(myURL, Infinity), expectedErr); + [true, 1, 'test', Infinity].forEach((value) => { + assert.throws( + () => url.format(myURL, value), + { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "options" argument must be of type Object. ' + + `Received type ${typeof value}` + } + ); + }); } // Any falsy value other than undefined will be treated as false. diff --git a/test/parallel/test-url-parse-invalid-input.js b/test/parallel/test-url-parse-invalid-input.js index d2c7a1135a..0f113862c7 100644 --- a/test/parallel/test-url-parse-invalid-input.js +++ b/test/parallel/test-url-parse-invalid-input.js @@ -6,7 +6,7 @@ const url = require('url'); // https://github.com/joyent/node/issues/568 [ [undefined, 'undefined'], - [null, 'null'], + [null, 'object'], [true, 'boolean'], [false, 'boolean'], [0.0, 'number'], diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js index d8b2de314c..9be3b132f9 100644 --- a/test/parallel/test-util-callbackify.js +++ b/test/parallel/test-util-callbackify.js @@ -236,7 +236,8 @@ const values = [ }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "original" argument must be of type Function' + message: 'The "original" argument must be of type Function. ' + + `Received type ${typeof value}` }); }); } @@ -257,7 +258,8 @@ const values = [ }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The last argument must be of type Function' + message: 'The last argument must be of type Function. ' + + `Received type ${typeof value}` }); }); } diff --git a/test/parallel/test-util-deprecate-invalid-code.js b/test/parallel/test-util-deprecate-invalid-code.js index 057e095424..635bab4252 100644 --- a/test/parallel/test-util-deprecate-invalid-code.js +++ b/test/parallel/test-util-deprecate-invalid-code.js @@ -7,6 +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' + message: 'The "code" argument must be of type string. ' + + `Received type ${typeof notString}` }); }); diff --git a/test/parallel/test-util-inherits.js b/test/parallel/test-util-inherits.js index afbd504beb..9d89022088 100644 --- a/test/parallel/test-util-inherits.js +++ b/test/parallel/test-util-inherits.js @@ -74,13 +74,14 @@ assert.strictEqual(e.d(), 'd'); assert.strictEqual(e.e(), 'e'); assert.strictEqual(e.constructor, E); -// should throw with invalid arguments +// Should throw with invalid arguments common.expectsError(function() { inherits(A, {}); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "superCtor.prototype" property must be of type Function' + message: 'The "superCtor.prototype" property must be of type Function. ' + + 'Received type undefined' }); common.expectsError(function() { @@ -88,7 +89,8 @@ common.expectsError(function() { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "superCtor" argument must be of type Function' + message: 'The "superCtor" argument must be of type Function. ' + + 'Received type object' }); common.expectsError(function() { @@ -96,5 +98,5 @@ common.expectsError(function() { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "ctor" argument must be of type Function' + message: 'The "ctor" argument must be of type Function. Received type object' }); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index b2c8207de5..0dd1ad74c0 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1134,7 +1134,8 @@ if (typeof Symbol !== 'undefined') { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type Object' + message: 'The "options" argument must be of type Object. ' + + 'Received type object' } ); @@ -1143,7 +1144,8 @@ if (typeof Symbol !== 'undefined') { }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "options" argument must be of type Object' + message: 'The "options" argument must be of type Object. ' + + 'Received type string' } ); } diff --git a/test/parallel/test-util-promisify.js b/test/parallel/test-util-promisify.js index 235d5c40db..5e1994a730 100644 --- a/test/parallel/test-util-promisify.js +++ b/test/parallel/test-util-promisify.js @@ -191,6 +191,7 @@ const stat = promisify(fs.stat); { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "original" argument must be of type Function' + message: 'The "original" argument must be of type Function. ' + + `Received type ${typeof input}` }); }); diff --git a/test/parallel/test-v8-flag-type-check.js b/test/parallel/test-v8-flag-type-check.js index 67a34b51f2..1dcdee928b 100644 --- a/test/parallel/test-v8-flag-type-check.js +++ b/test/parallel/test-v8-flag-type-check.js @@ -2,13 +2,14 @@ const common = require('../common'); const v8 = require('v8'); -[ 1, undefined ].forEach((i) => { +[1, undefined].forEach((value) => { common.expectsError( - () => v8.setFlagsFromString(i), + () => v8.setFlagsFromString(value), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "flags" argument must be of type string' + message: 'The "flags" argument must be of type string. ' + + `Received type ${typeof value}` } ); }); diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js index 3a74cb38d2..bf1532cacc 100644 --- a/test/parallel/test-vm-basic.js +++ b/test/parallel/test-vm-basic.js @@ -71,54 +71,35 @@ const context2 = vm.createContext(sandbox3); assert.strictEqual(sandbox3, context2); // Test 6: invalid arguments -common.expectsError(() => { - vm.createContext({}, null); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options" argument must be of type object. Received type null' +[null, 'string'].forEach((input) => { + common.expectsError(() => { + vm.createContext({}, input); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "options" argument must be of type object. ' + + `Received type ${typeof input}` + }); }); -common.expectsError(() => { - vm.createContext({}, 'string'); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options" argument must be of type object. Received type string' +['name', 'origin'].forEach((propertyName) => { + common.expectsError(() => { + vm.createContext({}, { [propertyName]: null }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: `The "options.${propertyName}" property must be of type string. ` + + 'Received type object' + }); }); -common.expectsError(() => { - vm.createContext({}, { name: null }); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options.name" property must be of type string. ' + - 'Received type null' -}); - -common.expectsError(() => { - vm.createContext({}, { origin: null }); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options.origin" property must be of type string. ' + - 'Received type null' -}); - -common.expectsError(() => { - vm.runInNewContext('', {}, { contextName: null }); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options.contextName" property must be of type string. ' + - 'Received type null' -}); - -common.expectsError(() => { - vm.runInNewContext('', {}, { contextOrigin: null }); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options.contextOrigin" property must be of type string. ' + - 'Received type null' +['contextName', 'contextOrigin'].forEach((propertyName) => { + common.expectsError(() => { + vm.runInNewContext('', {}, { [propertyName]: null }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: `The "options.${propertyName}" property must be of type string. ` + + 'Received type object' + }); }); diff --git a/test/parallel/test-zlib-not-string-or-buffer.js b/test/parallel/test-zlib-not-string-or-buffer.js index 489bc07f5d..bf59e86d5c 100644 --- a/test/parallel/test-zlib-not-string-or-buffer.js +++ b/test/parallel/test-zlib-not-string-or-buffer.js @@ -6,14 +6,24 @@ const common = require('../common'); const zlib = require('zlib'); -[undefined, null, true, false, 0, 1, [1, 2, 3], { foo: 'bar' }].forEach((i) => { +[ + undefined, + null, + true, + false, + 0, + 1, + [1, 2, 3], + { foo: 'bar' } +].forEach((input) => { common.expectsError( - () => zlib.deflateSync(i), + () => zlib.deflateSync(input), { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "buffer" argument must be one of type string, Buffer, ' + - 'TypedArray, DataView, or ArrayBuffer' + 'TypedArray, DataView, or ArrayBuffer. ' + + `Received type ${typeof input}` } ); }); diff --git a/test/sequential/test-crypto-timing-safe-equal.js b/test/sequential/test-crypto-timing-safe-equal.js index 08cfc04755..6aaf7de228 100644 --- a/test/sequential/test-crypto-timing-safe-equal.js +++ b/test/sequential/test-crypto-timing-safe-equal.js @@ -33,7 +33,8 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "a" argument must be one of type Buffer, TypedArray, or DataView' + 'The "buf1" argument must be one of type Buffer, TypedArray, or ' + + 'DataView. Received type string' } ); @@ -43,6 +44,7 @@ common.expectsError( code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: - 'The "b" argument must be one of type Buffer, TypedArray, or DataView' + 'The "buf2" argument must be one of type Buffer, TypedArray, or ' + + 'DataView. Received type string' } ); -- cgit v1.2.3