Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-03-19 15:33:46 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2018-03-25 03:45:37 +0300
commitc6b6c92185316e13738e6fa931fdd5303e381e46 (patch)
treec38af9cd1a0a8cd6eeb459af3adee4dfd390fdc6 /lib
parenteeb57022e6bada13955a19b15232a9ee4fe9b465 (diff)
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 <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/_http_outgoing.js9
-rw-r--r--lib/_stream_readable.js3
-rw-r--r--lib/_stream_writable.js2
-rw-r--r--lib/_tls_common.js7
-rw-r--r--lib/_tls_wrap.js4
-rw-r--r--lib/async_hooks.js2
-rw-r--r--lib/buffer.js28
-rw-r--r--lib/dgram.js22
-rw-r--r--lib/events.js8
-rw-r--r--lib/fs/promises.js2
-rw-r--r--lib/internal/crypto/certificate.js9
-rw-r--r--lib/internal/crypto/cipher.js35
-rw-r--r--lib/internal/crypto/diffiehellman.js10
-rw-r--r--lib/internal/crypto/hash.js9
-rw-r--r--lib/internal/crypto/pbkdf2.js12
-rw-r--r--lib/internal/crypto/random.js4
-rw-r--r--lib/internal/crypto/sig.js16
-rw-r--r--lib/internal/crypto/util.js20
-rw-r--r--lib/internal/encoding.js8
-rw-r--r--lib/internal/errors.js10
-rw-r--r--lib/internal/fs.js5
-rw-r--r--lib/internal/http2/compat.js10
-rw-r--r--lib/internal/http2/core.js24
-rw-r--r--lib/internal/http2/util.js2
-rw-r--r--lib/internal/modules/esm/Loader.js6
-rw-r--r--lib/internal/modules/esm/ModuleMap.js8
-rw-r--r--lib/internal/process.js4
-rw-r--r--lib/internal/process/warning.js6
-rw-r--r--lib/internal/url.js2
-rw-r--r--lib/internal/util.js4
-rw-r--r--lib/internal/vm/Module.js3
-rw-r--r--lib/path.js6
-rw-r--r--lib/perf_hooks.js6
-rw-r--r--lib/string_decoder.js3
-rw-r--r--lib/util.js13
-rw-r--r--lib/v8.js2
-rw-r--r--lib/zlib.js3
37 files changed, 187 insertions, 140 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index 9cb9c29b365..2af2fddb62b 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 434dabd8837..0b6cf10aac2 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 5692cae1954..df1d4076d02 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 f63acad8ad1..b669badb701 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 839aba555be..41dd001bd6a 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 3a79da27da4..345b003e549 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 c11762aa57c..a13ada73ce6 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 b9caeddabe2..355e7d2fbe7 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 46761653a01..46d1223e69a 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 8884777e5e1..c3c3c3e4db7 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 5eaa5ce0564..35325874ba2 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 73118ffebb0..cd8297245fe 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 793f3fb3514..527d8b07e13 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 41e00b88b9c..d172a6a3c8e 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 fdffcffad68..de41be42281 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 77ad06ee7b5..95e38dcc443 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 688ad43dddd..aed679e99b9 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 19c35ac4cdf..095ca0478bd 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 9cd47f861f9..ae874c530cc 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 ee7b78b66b8..9487a84e03f 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 36155d4d67f..21ab1048d79 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 6ec6cb33cb7..78fedcb2ce5 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 9978df87d6d..89cc8db0b00 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 b9bd580af27..bf5d0721939 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 84c23cc10ac..e10296cce2d 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 e9a8d22d7bf..985d24dc8d3 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 573ffc1600f..f1224665c5f 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 8c0a503239b..a970b622c89 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 0579cac16ce..239a17e483f 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 89bba47c902..247ac2dd5a7 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 feb4bb190f7..48d591f3bf8 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 427d158e7a7..90129f1f529 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 e4c2a985e4b..7fa5501b28c 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 a6ae64c0624..b32249ad9e5 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 eabdf6c1df6..2cf79bb5f08 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 0e2a6533dc8..cce77c5062a 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 3660bd1a7d2..f2233beb031 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
);
}
}