summaryrefslogtreecommitdiff
path: root/lib/internal
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-03-19 13:33:46 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-03-25 01:45:37 +0100
commitc6b6c92185316e13738e6fa931fdd5303e381e46 (patch)
treec38af9cd1a0a8cd6eeb459af3adee4dfd390fdc6 /lib/internal
parenteeb57022e6bada13955a19b15232a9ee4fe9b465 (diff)
downloadandroid-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.tar.gz
android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.tar.bz2
android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.zip
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/internal')
-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
21 files changed, 119 insertions, 88 deletions
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);
}
}