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>
This commit is contained in:
Родитель
eeb57022e6
Коммит
c6b6c92185
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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().
|
||||
|
|
22
lib/dgram.js
22
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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) ||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
13
lib/util.js
13
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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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 ?
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
||||
{
|
||||
|
|
|
@ -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}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
[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}`
|
||||
};
|
||||
|
||||
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'
|
||||
}
|
||||
);
|
||||
assert.throws(() => sign.sign(input), errObj);
|
||||
assert.throws(() => verify.verify(input), errObj);
|
||||
|
||||
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'
|
||||
}
|
||||
);
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
// Check valid addresses
|
||||
[false, '', null, 0, undefined].forEach((address) => {
|
||||
client.send(buf, port, address, 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);
|
||||
|
||||
// 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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
||||
{
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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]'
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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}`
|
||||
}
|
||||
)
|
||||
);
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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',
|
||||
type: TypeError,
|
||||
message: params[2]
|
||||
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',
|
||||
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}`
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -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'), {
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -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]) => {
|
||||
[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$/
|
||||
});
|
||||
});
|
||||
|
||||
// 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]) => {
|
||||
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}`
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ const url = require('url');
|
|||
|
||||
const throwsObjsAndReportTypes = new Map([
|
||||
[undefined, 'undefined'],
|
||||
[null, 'null'],
|
||||
[null, 'object'],
|
||||
[true, 'boolean'],
|
||||
[false, 'boolean'],
|
||||
[0, 'number'],
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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}`
|
||||
});
|
||||
});
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче