errors: improve ERR_INVALID_ARG_TYPE

ERR_INVALID_ARG_TYPE is the most common error used throughout the
code base. This improves the error message by providing more details
to the user and by indicating more precisely which values are allowed
ones and which ones are not.

It adds the actual input to the error message in case it's a primitive.
If it's a class instance, it'll print the class name instead of
"object" and "falsy" or similar entries are not named "type" anymore.

PR-URL: https://github.com/nodejs/node/pull/29675
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Ruben Bridgewater committed 2019-12-20 03:10:13 +01:00
1 parent fc28761d77
commit ac2fc0dd5f
127 files changed
+665 -534

No files matched your search

+124 -34
View File
@@ -23,6 +23,21 @@ const {
const messages = new Map();
const codes = {};
const classRegExp = /^([A-Z][a-z0-9]*)+$/;
// Sorted by a rough estimate on most frequently used entries.
const kTypes = [
'string',
'function',
'number',
'object',
// Accept 'Function' and 'Object' as alternative to the lower cased version.
'Function',
'Object',
'boolean',
'bigint',
'symbol'
];
const { kMaxLength } = internalBinding('buffer');
const MainContextError = Error;
@@ -610,26 +625,6 @@ function isStackOverflowError(err) {
err.message === maxStack_ErrorMessage;
}
function oneOf(expected, thing) {
assert(typeof thing === 'string', '`thing` has to be of type string');
if (ArrayIsArray(expected)) {
const len = expected.length;
assert(len > 0,
'At least one expected value needs to be specified');
expected = expected.map((i) => String(i));
if (len > 2) {
return `one of ${thing} ${expected.slice(0, len - 1).join(', ')}, or ` +
expected[len - 1];
} else if (len === 2) {
return `one of ${thing} ${expected[0]} or ${expected[1]}`;
} else {
return `of ${thing} ${expected[0]}`;
}
} else {
return `of ${thing} ${String(expected)}`;
}
}
// Only use this for integers! Decimal numbers do not work with this function.
function addNumericalSeparator(val) {
let res = '';
@@ -926,27 +921,114 @@ E('ERR_INVALID_ADDRESS_FAMILY', function(addressType, host, port) {
E('ERR_INVALID_ARG_TYPE',
(name, expected, actual) => {
assert(typeof name === 'string', "'name' must be a string");
// determiner: 'must be' or 'must not be'
let determiner;
if (typeof expected === 'string' && expected.startsWith('not ')) {
determiner = 'must not be';
expected = expected.replace(/^not /, '');
} else {
determiner = 'must be';
if (!ArrayIsArray(expected)) {
expected = [expected];
}
let msg;
let msg = 'The ';
if (name.endsWith(' argument')) {
// For cases like 'first argument'
msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
msg += `${name} `;
} else {
const type = name.includes('.') ? 'property' : 'argument';
msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, 'type')}`;
msg += `"${name}" ${type} `;
}
// TODO(BridgeAR): Improve the output by showing `null` and similar.
msg += `. Received type ${typeof actual}`;
// determiner: 'must be' or 'must not be'
if (typeof expected === 'string' && expected.startsWith('not ')) {
msg += 'must not be ';
expected = expected.replace(/^not /, '');
} else {
msg += 'must be ';
}
const types = [];
const instances = [];
const other = [];
for (const value of expected) {
assert(typeof value === 'string',
'All expected entries have to be of type string');
if (kTypes.includes(value)) {
types.push(value.toLowerCase());
} else if (classRegExp.test(value)) {
instances.push(value);
} else {
assert(value !== 'object',
'The value "object" should be written as "Object"');
other.push(value);
}
}
// Special handle `object` in case other instances are allowed to outline
// the differences between each other.
if (instances.length > 0) {
const pos = types.indexOf('object');
if (pos !== -1) {
types.splice(pos, 1);
instances.push('Object');
}
}
if (types.length > 0) {
if (types.length > 2) {
const last = types.pop();
msg += `one of type ${types.join(', ')}, or ${last}`;
} else if (types.length === 2) {
msg += `one of type ${types[0]} or ${types[1]}`;
} else {
msg += `of type ${types[0]}`;
}
if (instances.length > 0 || other.length > 0)
msg += ' or ';
}
if (instances.length > 0) {
if (instances.length > 2) {
const last = instances.pop();
msg += `an instance of ${instances.join(', ')}, or ${last}`;
} else {
msg += `an instance of ${instances[0]}`;
if (instances.length === 2) {
msg += ` or ${instances[1]}`;
}
}
if (other.length > 0)
msg += ' or ';
}
if (other.length > 0) {
if (other.length > 2) {
const last = other.pop();
msg += `one of ${other.join(', ')}, or ${last}`;
} else if (other.length === 2) {
msg += `one of ${other[0]} or ${other[1]}`;
} else {
if (other[0].toLowerCase() !== other[0])
msg += 'an ';
msg += `${other[0]}`;
}
}
if (actual == null) {
msg += `. Received ${actual}`;
} else if (typeof actual === 'function' && actual.name) {
msg += `. Received function ${actual.name}`;
} else if (typeof actual === 'object') {
if (actual.constructor && actual.constructor.name) {
msg += `. Received an instance of ${actual.constructor.name}`;
} else {
const inspected = lazyInternalUtilInspect()
.inspect(actual, { depth: -1 });
msg += `. Received ${inspected}`;
}
} else {
let inspected = lazyInternalUtilInspect()
.inspect(actual, { colors: false });
if (inspected.length > 25)
inspected = `${inspected.slice(0, 25)}...`;
msg += `. Received type ${typeof actual} (${inspected})`;
}
return msg;
}, TypeError);
E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
@@ -1034,7 +1116,15 @@ E('ERR_INVALID_URL', function(input) {
return `Invalid URL: ${input}`;
}, TypeError);
E('ERR_INVALID_URL_SCHEME',
(expected) => `The URL must be ${oneOf(expected, 'scheme')}`, TypeError);
(expected) => {
if (typeof expected === 'string')
expected = [expected];
assert(expected.length <= 2);
const res = expected.length === 2 ?
`one of scheme ${expected[0]} or ${expected[1]}` :
`of scheme ${expected[0]}`;
return `The URL must be ${res}`;
}, TypeError);
E('ERR_IPC_CHANNEL_CLOSED', 'Channel closed', Error);
E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected', Error);
E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe', Error);
+21
View File
@@ -718,6 +718,26 @@ function runWithInvalidFD(func) {
printSkipMessage('Could not generate an invalid fd');
}
// A helper function to simplify checking for ERR_INVALID_ARG_TYPE output.
function invalidArgTypeHelper(input) {
if (input == null) {
return ` Received ${input}`;
}
if (typeof input === 'function' && input.name) {
return ` Received function ${input.name}`;
}
if (typeof input === 'object') {
if (input.constructor && input.constructor.name) {
return ` Received an instance of ${input.constructor.name}`;
}
return ` Received ${util.inspect(input, { depth: -1 })}`;
}
let inspected = util.inspect(input, { colors: false });
if (inspected.length > 25)
inspected = `${inspected.slice(0, 25)}...`;
return ` Received type ${typeof input} (${inspected})`;
}
module.exports = {
allowGlobals,
buildType,
@@ -735,6 +755,7 @@ module.exports = {
hasIntl,
hasCrypto,
hasMultiLocalhost,
invalidArgTypeHelper,
isAIX,
isAlive,
isFreeBSD,
+8 -5
View File
@@ -25,7 +25,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "url" argument must be of type string. Received type number'
message: 'The "url" argument must be of type string. Received type number' +
' (1)'
}
);
@@ -34,7 +35,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "url" argument must be of type string. Received type number'
message: 'The "url" argument must be of type string. Received type number' +
' (1)'
}
);
@@ -43,8 +45,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "job" argument must be of type ModuleJob. ' +
'Received type string'
message: 'The "job" argument must be an instance of ModuleJob. ' +
"Received type string ('notamodulejob')"
}
);
@@ -53,6 +55,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "url" argument must be of type string. Received type number'
message: 'The "url" argument must be of type string. Received type number' +
' (1)'
}
);
+1 -1
View File
@@ -26,7 +26,7 @@ const dnsPromises = require('dns').promises;
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "rrtype" argument must be of type string. ' +
`Received type ${typeof rrtype}`
`Received type ${typeof rrtype} (${rrtype})`
}
);
}
+4 -4
View File
@@ -125,8 +125,8 @@ promises.push(assert.rejects(
assert.rejects('fail', {}),
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "promiseFn" argument must be one of type ' +
'Function or Promise. Received type string'
message: 'The "promiseFn" argument must be of type function or an ' +
"instance of Promise. Received type string ('fail')"
}
));
@@ -225,8 +225,8 @@ promises.push(assert.rejects(
assert.doesNotReject(123),
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "promiseFn" argument must be one of type ' +
'Function or Promise. Received type number'
message: 'The "promiseFn" argument must be of type ' +
'function or an instance of Promise. Received type number (123)'
}
));
/* eslint-enable no-restricted-syntax */
+12 -10
View File
@@ -414,8 +414,8 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "fn" argument must be of type Function. Received ' +
`type ${typeof fn}`
message: 'The "fn" argument must be of type function.' +
common.invalidArgTypeHelper(fn)
}
);
};
@@ -484,8 +484,8 @@ assert.throws(() => {
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options" argument must be of type Object. ' +
`Received type ${typeof input}`
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(input)
});
});
}
@@ -937,8 +937,9 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "error" argument must be one of type Object, Error, ' +
'Function, or RegExp. Received type string'
message: 'The "error" argument must be of type function or ' +
'an instance of Error, RegExp, or Object. Received type string ' +
"('Error message')"
}
);
@@ -951,8 +952,9 @@ common.expectsError(
() => assert.throws(() => {}, input),
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "error" argument must be one of type Object, Error, ' +
`Function, or RegExp. Received type ${typeof input}`
message: 'The "error" argument must be of type function or ' +
'an instance of Error, RegExp, or Object.' +
common.invalidArgTypeHelper(input)
}
);
});
@@ -1030,8 +1032,8 @@ common.expectsError(
{
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "expected" argument must be one of type Function or ' +
'RegExp. Received type object'
message: 'The "expected" argument must be of type function or an ' +
'instance of RegExp. Received an instance of Object'
}
);
+6 -6
View File
@@ -967,19 +967,19 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "target" argument must be one of type Buffer or Uint8Array.' +
' Received type undefined'
message: 'The "target" argument must be an instance of Buffer or ' +
'Uint8Array. Received undefined'
});
assert.throws(() => Buffer.from(), {
name: 'TypeError',
message: 'The first argument must be one of type string, Buffer, ' +
'ArrayBuffer, Array, or Array-like Object. Received type undefined'
message: 'The first argument must be of type string or an instance of ' +
'Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined'
});
assert.throws(() => Buffer.from(null), {
name: 'TypeError',
message: 'The first argument must be one of type string, Buffer, ' +
'ArrayBuffer, Array, or Array-like Object. Received type object'
message: 'The first argument must be of type string or an instance of ' +
'Buffer, ArrayBuffer, or Array or an Array-like Object. Received null'
});
// Test prototype getters don't throw
+3 -2
View File
@@ -43,8 +43,9 @@ assert.throws(function() {
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The first argument must be one of type string, Buffer,' +
' ArrayBuffer, Array, or Array-like Object. Received type object'
message: 'The first argument must be of type string or an instance of ' +
'Buffer, ArrayBuffer, or Array or an Array-like Object. Received ' +
'an instance of AB'
});
// Test the byteOffset and length arguments
+3 -2
View File
@@ -16,8 +16,9 @@ const vm = require('vm');
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "string" argument must be one of type string, ' +
`Buffer, or ArrayBuffer. Received type ${typeof args[0]}`
message: 'The "string" argument must be of type string or an instance ' +
'of Buffer or ArrayBuffer.' +
common.invalidArgTypeHelper(args[0])
}
);
});
+2 -2
View File
@@ -89,6 +89,6 @@ assert.throws(() => a.compare(b, -Infinity, Infinity), oor);
common.expectsError(() => a.compare(), {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "target" argument must be one of ' +
'type Buffer or Uint8Array. Received type undefined'
message: 'The "target" argument must be an instance of ' +
'Buffer or Uint8Array. Received undefined'
});
+6 -6
View File
@@ -30,18 +30,18 @@ assert.strictEqual(Buffer.compare(Buffer.alloc(1), Buffer.alloc(0)), 1);
assert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'), {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "buf2" argument must be one of type Buffer or Uint8Array. ' +
'Received type string'
message: 'The "buf2" argument must be an instance of Buffer or Uint8Array. ' +
"Received type string ('abc')"
});
assert.throws(() => Buffer.compare('abc', Buffer.alloc(1)), {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "buf1" argument must be one of type Buffer or Uint8Array. ' +
'Received type string'
message: 'The "buf1" argument must be an instance of Buffer or Uint8Array. ' +
"Received type string ('abc')"
});
common.expectsError(() => Buffer.alloc(1).compare('abc'), {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "target" argument must be one of ' +
'type Buffer or Uint8Array. Received type string'
message: 'The "target" argument must be an instance of ' +
"Buffer or Uint8Array. Received type string ('abc')"
});
+6 -6
View File
@@ -49,8 +49,8 @@ assert.strictEqual(flatLongLen.toString(), check);
Buffer.concat(value);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "list" argument must be of type Array. ' +
`Received type ${typeof value}`
message: 'The "list" argument must be an instance of Array.' +
`${common.invalidArgTypeHelper(value)}`
});
});
@@ -59,8 +59,8 @@ assert.strictEqual(flatLongLen.toString(), check);
Buffer.concat(value);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "list[0]" argument must be one of type Buffer ' +
`or Uint8Array. Received type ${typeof value[0]}`
message: 'The "list[0]" argument must be an instance of Buffer ' +
`or Uint8Array.${common.invalidArgTypeHelper(value[0])}`
});
});
@@ -68,8 +68,8 @@ assert.throws(() => {
Buffer.concat([Buffer.from('hello'), 3]);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "list[1]" argument must be one of type Buffer ' +
'or Uint8Array. Received type number'
message: 'The "list[1]" argument must be an instance of Buffer ' +
'or Uint8Array. Received type number (3)'
});
// eslint-disable-next-line node-core/crypto-check
+2 -2
View File
@@ -19,7 +19,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "otherBuffer" argument must be one of type ' +
'Buffer or Uint8Array. Received type string'
message: 'The "otherBuffer" argument must be an instance of ' +
"Buffer or Uint8Array. Received type string ('abc')"
}
);
+3 -2
View File
@@ -196,7 +196,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "encoding" argument must be of type ' +
`string. Received type ${args[3] === null ? 'null' : typeof args[3]}`
`string.${common.invalidArgTypeHelper(args[3])}`
}
);
});
@@ -342,7 +342,8 @@ assert.strictEqual(
Buffer.alloc(1).fill(Buffer.alloc(1), 0, end);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "end" argument must be of type number. Received type object'
message: 'The "end" argument must be of type number. Received an ' +
'instance of Object'
});
}
+18 -18
View File
@@ -1,6 +1,6 @@
'use strict';
require('../common');
const common = require('../common');
const { deepStrictEqual, throws } = require('assert');
const { runInNewContext } = require('vm');
@@ -35,26 +35,26 @@ deepStrictEqual(
);
[
[{}, 'object'],
[new Boolean(true), 'boolean'],
[{ valueOf() { return null; } }, 'object'],
[{ valueOf() { return undefined; } }, 'object'],
[{ valueOf: null }, 'object'],
[Object.create(null), 'object'],
[new Number(true), 'number'],
[new MyBadPrimitive(), 'number'],
[Symbol(), 'symbol'],
[5n, 'bigint'],
[(one, two, three) => {}, 'function'],
[undefined, 'undefined'],
[null, 'object']
].forEach(([input, actualType]) => {
{},
new Boolean(true),
{ valueOf() { return null; } },
{ valueOf() { return undefined; } },
{ valueOf: null },
Object.create(null),
new Number(true),
new MyBadPrimitive(),
Symbol(),
5n,
(one, two, three) => {},
undefined,
null
].forEach((input) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The first argument must be one of type string, Buffer, ' +
'ArrayBuffer, Array, or Array-like Object. Received ' +
`type ${actualType}`
message: 'The first argument must be of type string or an instance of ' +
'Buffer, ArrayBuffer, or Array or an Array-like Object.' +
common.invalidArgTypeHelper(input)
};
throws(() => Buffer.from(input), errObj);
throws(() => Buffer.from(input, 'hex'), errObj);
+3 -2
View File
@@ -282,8 +282,9 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "value" argument must be one of type number, string, ' +
`Buffer, or Uint8Array. Received type ${typeof val}`
message: 'The "value" argument must be one of type number or string ' +
'or an instance of Buffer or Uint8Array.' +
common.invalidArgTypeHelper(val)
}
);
});
+3 -2
View File
@@ -357,8 +357,9 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1);
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "value" argument must be one of type number, string, ' +
`Buffer, or Uint8Array. Received type ${typeof val}`
message: 'The "value" argument must be one of type number or string ' +
'or an instance of Buffer or Uint8Array.' +
common.invalidArgTypeHelper(val)
}
);
});
+2 -1
View File
@@ -5,5 +5,6 @@ const common = require('../common');
common.expectsError(() => new Buffer(42, 'utf8'), {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "string" argument must be of type string. Received type number'
message: 'The "string" argument must be of type string. Received type ' +
'number (42)'
});
@@ -5,10 +5,6 @@ const assert = require('assert');
const { ChildProcess } = require('child_process');
assert.strictEqual(typeof ChildProcess, 'function');
function typeName(value) {
return typeof value;
}
{
// Verify that invalid options to spawn() throw.
const child = new ChildProcess();
@@ -19,8 +15,8 @@ function typeName(value) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be of type Object. ' +
`Received type ${typeName(options)}`
message: 'The "options" argument must be of type object.' +
`${common.invalidArgTypeHelper(options)}`
});
});
}
@@ -35,8 +31,8 @@ function typeName(value) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.file" property must be of type string. ' +
`Received type ${typeName(file)}`
message: 'The "options.file" property must be of type string.' +
`${common.invalidArgTypeHelper(file)}`
});
});
}
@@ -51,8 +47,8 @@ function typeName(value) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.envPairs" property must be of type Array. ' +
`Received type ${typeName(envPairs)}`
message: 'The "options.envPairs" property must be an instance of Array.' +
common.invalidArgTypeHelper(envPairs)
});
});
}
@@ -67,8 +63,8 @@ function typeName(value) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.args" property must be of type Array. ' +
`Received type ${typeName(args)}`
message: 'The "options.args" property must be an instance of Array.' +
common.invalidArgTypeHelper(args)
});
});
}
+1 -1
View File
@@ -52,7 +52,7 @@ assert.throws(() => n.send(), {
assert.throws(() => n.send(Symbol()), {
name: 'TypeError',
message: 'The "message" argument must be one of type string,' +
' object, number, or boolean. Received type symbol',
' object, number, or boolean. Received type symbol (Symbol())',
code: 'ERR_INVALID_ARG_TYPE'
});
n.send({ hello: 'world' });
+1 -1
View File
@@ -141,7 +141,7 @@ out.write = err.write = (d) => {};
},
{
message: 'The "inspectOptions" argument must be of type object.' +
` Received type ${typeof inspectOptions}`,
common.invalidArgTypeHelper(inspectOptions),
code: 'ERR_INVALID_ARG_TYPE'
}
);
+5 -4
View File
@@ -75,8 +75,8 @@ assert(Certificate() instanceof Certificate);
() => Certificate.verifySpkac(val),
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "spkac" argument must be one of type Buffer, TypedArray, ' +
`or DataView. Received type ${typeof val}`
message: 'The "spkac" argument must be an instance of Buffer, ' +
`TypedArray, or DataView.${common.invalidArgTypeHelper(val)}`
}
);
});
@@ -84,8 +84,9 @@ assert(Certificate() instanceof Certificate);
[1, {}, [], Infinity, true, undefined, null].forEach((val) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "spkac" argument must be one of type string, Buffer,' +
` TypedArray, or DataView. Received type ${typeof val}`
message: 'The "spkac" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(val)
};
assert.throws(() => Certificate.exportPublicKey(val), errObj);
assert.throws(() => Certificate.exportChallenge(val), errObj);
+12 -12
View File
@@ -91,7 +91,7 @@ testCipher2(Buffer.from('0123456789abcdef'));
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "cipher" argument must be of type string. ' +
'Received type object'
'Received null'
});
common.expectsError(
@@ -99,8 +99,8 @@ testCipher2(Buffer.from('0123456789abcdef'));
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "password" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type object'
message: 'The "password" argument must be of type string or an instance' +
' of Buffer, TypedArray, or DataView. Received null'
});
common.expectsError(
@@ -108,8 +108,8 @@ testCipher2(Buffer.from('0123456789abcdef'));
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "data" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type object'
message: 'The "data" argument must be of type string or an instance' +
' of Buffer, TypedArray, or DataView. Received null'
});
common.expectsError(
@@ -117,8 +117,8 @@ testCipher2(Buffer.from('0123456789abcdef'));
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer" argument must be one of type Buffer, ' +
'TypedArray, or DataView. Received type object'
message: 'The "buffer" argument must be an instance' +
' of Buffer, TypedArray, or DataView. Received null'
});
}
@@ -134,7 +134,7 @@ testCipher2(Buffer.from('0123456789abcdef'));
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "cipher" argument must be of type string. ' +
'Received type object'
'Received null'
});
common.expectsError(
@@ -142,8 +142,8 @@ testCipher2(Buffer.from('0123456789abcdef'));
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer" argument must be one of type Buffer, ' +
'TypedArray, or DataView. Received type object'
message: 'The "buffer" argument must be an instance of Buffer, ' +
'TypedArray, or DataView. Received null'
});
common.expectsError(
@@ -151,8 +151,8 @@ testCipher2(Buffer.from('0123456789abcdef'));
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "password" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type object'
message: 'The "password" argument must be of type string or an ' +
'instance of Buffer, TypedArray, or DataView. Received null'
});
}
@@ -93,7 +93,7 @@ function testCipher3(key, iv) {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "cipher" argument must be of type string. ' +
'Received type object'
'Received null'
});
common.expectsError(
@@ -101,8 +101,8 @@ function testCipher3(key, iv) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "key" argument must be one of type Buffer, TypedArray, ' +
'DataView, string, or KeyObject. Received type object'
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, DataView, or KeyObject. Received null'
});
common.expectsError(
@@ -110,8 +110,8 @@ function testCipher3(key, iv) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "iv" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type number'
message: 'The "iv" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received type number (10)'
});
}
@@ -130,7 +130,7 @@ function testCipher3(key, iv) {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "cipher" argument must be of type string. ' +
'Received type object'
'Received null'
});
common.expectsError(
@@ -138,8 +138,8 @@ function testCipher3(key, iv) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "key" argument must be one of type Buffer, TypedArray, ' +
'DataView, string, or KeyObject. Received type object'
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, DataView, or KeyObject. Received null'
});
common.expectsError(
@@ -147,8 +147,8 @@ function testCipher3(key, iv) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "iv" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type number'
message: 'The "iv" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received type number (10)'
});
}
+4 -3
View File
@@ -53,8 +53,9 @@ assert.strictEqual(dh2.verifyError, 0);
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "sizeOrKey" argument must be one of type number, string, ' +
`Buffer, TypedArray, or DataView. Received type ${typeof input}`
message: 'The "sizeOrKey" argument must be one of type number or string' +
' or an instance of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(input)
}
);
});
@@ -381,7 +382,7 @@ common.expectsError(
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "curve" argument must be of type string. ' +
'Received type undefined'
'Received undefined'
});
assert.throws(
+4 -2
View File
@@ -12,7 +12,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "id" argument must be of type string. Received type boolean'
message: 'The "id" argument must be of type string. Received type boolean' +
' (true)'
});
common.expectsError(
@@ -20,7 +21,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "flags" argument must be of type number. Received type string'
message: 'The "flags" argument must be of type number. Received type' +
" string ('notANumber')"
});
common.expectsError(
+3 -3
View File
@@ -129,8 +129,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "data" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type undefined'
message: 'The "data" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received undefined'
});
// Default UTF-8 encoding
@@ -171,7 +171,7 @@ common.expectsError(
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "algorithm" argument must be of type string. ' +
'Received type undefined'
'Received undefined'
}
);
+3 -3
View File
@@ -18,7 +18,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "hmac" argument must be of type string. Received type object'
message: 'The "hmac" argument must be of type string. Received null'
});
// This used to segfault. See: https://github.com/nodejs/node/issues/9819
@@ -36,8 +36,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "key" argument must be one of type Buffer, TypedArray, ' +
'DataView, string, or KeyObject. Received type object'
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, DataView, or KeyObject. Received null'
});
function testHmac(algo, key, data, expected) {
+9 -7
View File
@@ -59,7 +59,8 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message:
'The "handle" argument must be of type object. Received type string'
'The "handle" argument must be of type object. Received type ' +
"string ('')"
});
}
@@ -102,8 +103,9 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
common.expectsError(() => createPrivateKey(createPublicKey(privatePem)), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "key" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type object'
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received an instance of ' +
'PublicKeyObject'
});
// Similarly, passing an existing private key object to createPrivateKey
@@ -112,8 +114,9 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
common.expectsError(() => createPrivateKey(privateKey), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "key" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type object'
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received an instance of ' +
'PrivateKeyObject'
});
}
@@ -139,8 +142,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
common.expectsError(() => publicKey.export(opt), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type object. Received type ' +
typeof opt
message: /^The "options" argument must be of type object/
});
}
+6 -6
View File
@@ -598,8 +598,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
common.expectsError(() => generateKeyPairSync(type, {}), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "type" argument must be of type string. Received type ' +
typeof type
message: 'The "type" argument must be of type string.' +
common.invalidArgTypeHelper(type)
});
}
@@ -615,8 +615,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
common.expectsError(() => generateKeyPair('rsa', common.mustNotCall()), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of ' +
'type object. Received type undefined'
message: 'The "options" argument must be of type object. ' +
'Received undefined'
});
// Even if no options are required, it should be impossible to pass anything
@@ -624,8 +624,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
common.expectsError(() => generateKeyPair('ed448', 0, common.mustNotCall()), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of ' +
'type object. Received type number'
message: 'The "options" argument must be of type object. ' +
'Received type number (0)'
});
}
+15 -15
View File
@@ -87,8 +87,8 @@ for (const iterations of [-1, 0]) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "keylen" argument must be of type number. ' +
`Received type ${typeof notNumber}`
message: 'The "keylen" argument must be of type number.' +
`${common.invalidArgTypeHelper(notNumber)}`
});
});
@@ -127,8 +127,8 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "digest" argument must be one of type string or null. ' +
'Received type undefined'
message: 'The "digest" argument must be of type string or null. ' +
'Received undefined'
});
assert.throws(
@@ -136,19 +136,19 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "digest" argument must be one of type string or null. ' +
'Received type undefined'
message: 'The "digest" argument must be of type string or null. ' +
'Received undefined'
});
[1, {}, [], true, undefined, null].forEach((input) => {
const msgPart2 = 'Buffer, TypedArray, or DataView.' +
` Received type ${typeof input}`;
const msgPart2 = 'an instance of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(input);
assert.throws(
() => crypto.pbkdf2(input, 'salt', 8, 8, 'sha256', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "password" argument must be one of type string, ${msgPart2}`
message: `The "password" argument must be of type string or ${msgPart2}`
}
);
@@ -157,7 +157,7 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "salt" argument must be one of type string, ${msgPart2}`
message: `The "salt" argument must be of type string or ${msgPart2}`
}
);
@@ -166,7 +166,7 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "password" argument must be one of type string, ${msgPart2}`
message: `The "password" argument must be of type string or ${msgPart2}`
}
);
@@ -175,19 +175,19 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "salt" argument must be one of type string, ${msgPart2}`
message: `The "salt" argument must be of type string or ${msgPart2}`
}
);
});
['test', {}, [], true, undefined, null].forEach((i) => {
const received = `Received type ${typeof i}`;
const received = common.invalidArgTypeHelper(i);
assert.throws(
() => crypto.pbkdf2('pass', 'salt', i, 8, 'sha256', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "iterations" argument must be of type number. ${received}`
message: `The "iterations" argument must be of type number.${received}`
}
);
@@ -196,7 +196,7 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "iterations" argument must be of type number. ${received}`
message: `The "iterations" argument must be of type number.${received}`
}
);
});
+4 -5
View File
@@ -46,8 +46,8 @@ common.expectWarning('DeprecationWarning',
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "size" argument must be of type number. ' +
`Received type ${typeof value}`
message: 'The "size" argument must be of type number.' +
common.invalidArgTypeHelper(value)
};
assert.throws(() => f(value), errObj);
assert.throws(() => f(value, common.mustNotCall()), errObj);
@@ -202,7 +202,7 @@ common.expectWarning('DeprecationWarning',
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "offset" argument must be of type number. ' +
'Received type string'
"Received type string ('test')"
};
assert.throws(() => crypto.randomFillSync(buf, 'test'), typeErrObj);
@@ -211,8 +211,7 @@ common.expectWarning('DeprecationWarning',
() => crypto.randomFill(buf, 'test', common.mustNotCall()),
typeErrObj);
typeErrObj.message = 'The "size" argument must be of type number. ' +
'Received type string';
typeErrObj.message = typeErrObj.message.replace('offset', 'size');
assert.throws(() => crypto.randomFillSync(buf, 0, 'test'), typeErrObj);
assert.throws(
+18 -17
View File
@@ -364,18 +364,18 @@ common.expectsError(
const verify = crypto.createVerify('SHA1');
[1, [], {}, undefined, null, true, Infinity].forEach((input) => {
const type = typeof input;
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "algorithm" argument must be of type string. ' +
`Received type ${type}`
message: 'The "algorithm" argument must be of type string.' +
`${common.invalidArgTypeHelper(input)}`
};
assert.throws(() => crypto.createSign(input), errObj);
assert.throws(() => crypto.createVerify(input), errObj);
errObj.message = 'The "data" argument must be one of type string, ' +
`Buffer, TypedArray, or DataView. Received type ${type}`;
errObj.message = 'The "data" argument must be of type string or an ' +
'instance of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(input);
assert.throws(() => sign.update(input), errObj);
assert.throws(() => verify.update(input), errObj);
assert.throws(() => sign._write(input, 'utf8', () => {}), errObj);
@@ -391,19 +391,20 @@ common.expectsError(
});
[1, {}, [], Infinity].forEach((input) => {
const type = typeof input;
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "key" argument must be one of type string, Buffer, ' +
`TypedArray, DataView, or KeyObject. Received type ${type}`
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, DataView, or KeyObject.' +
common.invalidArgTypeHelper(input)
};
assert.throws(() => sign.sign(input), errObj);
assert.throws(() => verify.verify(input), errObj);
errObj.message = 'The "signature" argument must be one of type string, ' +
`Buffer, TypedArray, or DataView. Received type ${type}`;
errObj.message = 'The "signature" argument must be of type string or an ' +
'instance of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(input);
assert.throws(() => verify.verify('test', input), errObj);
});
}
@@ -477,25 +478,25 @@ common.expectsError(
[1, {}, [], true, Infinity].forEach((input) => {
const data = Buffer.alloc(1);
const sig = Buffer.alloc(1);
const type = typeof input;
const received = common.invalidArgTypeHelper(input);
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "data" argument must be one of type Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
message: 'The "data" argument must be an instance of Buffer, ' +
`TypedArray, or DataView.${received}`
};
assert.throws(() => crypto.sign(null, input, 'asdf'), errObj);
assert.throws(() => crypto.verify(null, input, 'asdf', sig), errObj);
errObj.message = 'The "key" argument must be one of type string, Buffer, ' +
`TypedArray, DataView, or KeyObject. Received type ${type}`;
errObj.message = 'The "key" argument must be of type string or an instance ' +
`of Buffer, TypedArray, DataView, or KeyObject.${received}`;
assert.throws(() => crypto.sign(null, data, input), errObj);
assert.throws(() => crypto.verify(null, data, input, sig), errObj);
errObj.message = 'The "signature" argument must be one of type ' +
`Buffer, TypedArray, or DataView. Received type ${type}`;
errObj.message = 'The "signature" argument must be an instance of ' +
`Buffer, TypedArray, or DataView.${received}`;
assert.throws(() => crypto.verify(null, data, 'test', input), errObj);
});
+2 -2
View File
@@ -40,8 +40,8 @@ const dns = require('dns');
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "lookup" argument must be of type Function. ' +
`Received type ${typeof value}`
message: 'The "lookup" argument must be of type function.' +
common.invalidArgTypeHelper(value)
});
});
}
+2 -1
View File
@@ -40,7 +40,8 @@ socket.on('listening', common.mustCall(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "ttl" argument must be of type number. Received type string'
message: 'The "ttl" argument must be of type number. Received type string' +
" ('foo')"
});
// Close the socket
@@ -26,8 +26,8 @@ const client = dgram.createSocket('udp4').bind(0, () => {
const expectedError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "address" argument must be one of type string or falsy. ' +
`Received type ${typeof invalidInput}`
message: 'The "address" argument must be of type string or falsy.' +
`${common.invalidArgTypeHelper(invalidInput)}`
};
assert.throws(() => client.send(buf, port, invalidInput), expectedError);
});
@@ -35,8 +35,8 @@ function checkArgs(connected) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer" argument must be one of type ' +
'Buffer, Uint8Array, or string. Received type undefined'
message: 'The "buffer" argument must be of type string or an instance ' +
'of Buffer or Uint8Array. Received undefined'
}
);
@@ -89,8 +89,8 @@ function checkArgs(connected) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer" argument must be one of type ' +
'Buffer, Uint8Array, or string. Received type number'
message: 'The "buffer" argument must be of type string or an instance ' +
'of Buffer or Uint8Array. Received type number (23)'
}
);
@@ -100,8 +100,8 @@ function checkArgs(connected) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer list arguments" argument must be one of type ' +
'Buffer or string. Received type object'
message: 'The "buffer list arguments" argument must be of type string ' +
'or an instance of Buffer. Received an instance of Array'
}
);
}
+5 -5
View File
@@ -7,31 +7,31 @@ const socket = dgram.createSocket('udp4');
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "offset" argument must be of type number. Received type ' +
message: 'The "offset" argument must be of type number. Received ' +
'undefined'
};
assert.throws(() => socket.sendto(), errObj);
errObj.message = 'The "length" argument must be of type number. Received ' +
'type string';
"type string ('offset')";
assert.throws(
() => socket.sendto('buffer', 1, 'offset', 'port', 'address', 'cb'),
errObj);
errObj.message = 'The "offset" argument must be of type number. Received ' +
'type string';
"type string ('offset')";
assert.throws(
() => socket.sendto('buffer', 'offset', 1, 'port', 'address', 'cb'),
errObj);
errObj.message = 'The "address" argument must be of type string. Received ' +
'type boolean';
'type boolean (false)';
assert.throws(
() => socket.sendto('buffer', 1, 1, 10, false, 'cb'),
errObj);
errObj.message = 'The "port" argument must be of type number. Received ' +
'type boolean';
'type boolean (false)';
assert.throws(
() => socket.sendto('buffer', 1, 1, false, 'address', 'cb'),
errObj);
+2 -1
View File
@@ -14,7 +14,8 @@ socket.on('listening', common.mustCall(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "ttl" argument must be of type number. Received type string'
message: 'The "ttl" argument must be of type number. Received type string' +
" ('foo')"
});
// TTL must be a number from > 0 to < 256
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const { addresses } = require('../common/internet');
const assert = require('assert');
const dns = require('dns');
@@ -20,8 +20,8 @@ const promiseResolver = new dns.promises.Resolver();
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "servers" argument must be of type Array. Received type ' +
typeof val
message: 'The "servers" argument must be an instance of Array.' +
common.invalidArgTypeHelper(val)
};
assert.throws(
() => {
@@ -60,8 +60,8 @@ const promiseResolver = new dns.promises.Resolver();
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "servers[0]" argument must be of type string. ' +
`Received type ${typeof val[0]}`
message: 'The "servers[0]" argument must be of type string.' +
common.invalidArgTypeHelper(val[0])
};
assert.throws(
() => {
+3 -3
View File
@@ -144,7 +144,7 @@ assert.deepStrictEqual(dns.getServers(), []);
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "rrtype" argument must be of type string. ' +
'Received type object'
'Received an instance of Array'
};
common.expectsError(() => {
dns.resolve('example.com', [], common.mustNotCall());
@@ -158,7 +158,7 @@ assert.deepStrictEqual(dns.getServers(), []);
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "name" argument must be of type string. ' +
'Received type undefined'
'Received undefined'
};
common.expectsError(() => {
dnsPromises.resolve();
@@ -170,7 +170,7 @@ assert.deepStrictEqual(dns.getServers(), []);
const errorReg = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "hostname" argument must be of type string\. Received type .*/
message: /^The "hostname" argument must be of type string\. Received .*/
}, 10);
assert.throws(() => dns.lookup({}, common.mustNotCall()), errorReg);
@@ -92,6 +92,6 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "listener" argument must be of type Function. ' +
'Received type object'
message: 'The "listener" argument must be of type function. ' +
'Received null'
});
+2 -2
View File
@@ -56,8 +56,8 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "listener" argument must be of type Function. ' +
'Received type object'
message: 'The "listener" argument must be of type function. ' +
'Received null'
});
{
+2 -2
View File
@@ -25,8 +25,8 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "listener" argument must be of type Function. ' +
'Received type object'
message: 'The "listener" argument must be of type function. ' +
'Received null'
});
// Test fallback if prependListener is undefined.
@@ -151,8 +151,8 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "listener" argument must be of type Function. ' +
'Received type object'
message: 'The "listener" argument must be of type function. ' +
'Received null'
});
{
+2 -2
View File
@@ -25,8 +25,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "path" argument must be one of type string, Buffer, or URL.' +
' Received type boolean'
message: 'The "path" argument must be of type string or an instance of ' +
'Buffer or URL. Received type boolean (true)'
}
);
+3 -2
View File
@@ -151,8 +151,9 @@ if (fs.lchmod) {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "path" argument must be one of type string, Buffer, or URL.' +
` Received type ${typeof input}`
message: 'The "path" argument must be of type string or an instance ' +
'of Buffer or URL.' +
common.invalidArgTypeHelper(input)
};
assert.throws(() => fs.chmod(input, 1, common.mustNotCall()), errObj);
assert.throws(() => fs.chmodSync(input, 1), errObj);
+3 -3
View File
@@ -3,7 +3,7 @@
// This tests that the errors thrown from fs.close and fs.closeSync
// include the desired properties
require('../common');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
@@ -11,8 +11,8 @@ const fs = require('fs');
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof input}`
message: 'The "fd" argument must be of type number.' +
common.invalidArgTypeHelper(input)
};
assert.throws(() => fs.close(input), errObj);
assert.throws(() => fs.closeSync(input), errObj);
+3 -3
View File
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const util = require('util');
const fs = require('fs');
@@ -12,8 +12,8 @@ const fs = require('fs');
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "fd" argument must be of type number. Received type ' +
typeof input
message: 'The "fd" argument must be of type number.' +
common.invalidArgTypeHelper(input)
};
assert.throws(() => fs.fchmod(input), errObj);
assert.throws(() => fs.fchmodSync(input), errObj);
+1 -4
View File
@@ -23,13 +23,10 @@ function testGid(input, errObj) {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "fd" argument must be of type number. Received type ' +
typeof input
message: /fd|uid|gid/
};
testFd(input, errObj);
errObj.message = errObj.message.replace('fd', 'uid');
testUid(input, errObj);
errObj.message = errObj.message.replace('uid', 'gid');
testGid(input, errObj);
});
+1 -3
View File
@@ -54,9 +54,7 @@ fs.open(fileTemp, 'a', 0o777, common.mustCall(function(err, fd) {
['', false, null, undefined, {}, []].forEach((input) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "fd" argument must be of type number. Received type ' +
typeof input
name: 'TypeError'
};
assert.throws(() => fs.fdatasync(input), errObj);
assert.throws(() => fs.fdatasyncSync(input), errObj);
+5 -4
View File
@@ -217,13 +217,14 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
{
const pathname = path.join(tmpdir.path, nextdir());
['', 1, {}, [], null, Symbol('test'), () => {}].forEach((recursive) => {
const received = common.invalidArgTypeHelper(recursive);
common.expectsError(
() => fs.mkdir(pathname, { recursive }, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "recursive" argument must be of type boolean. Received ' +
`type ${typeof recursive}`
message: 'The "recursive" argument must be of type boolean.' +
received
}
);
common.expectsError(
@@ -231,8 +232,8 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "recursive" argument must be of type boolean. Received ' +
`type ${typeof recursive}`
message: 'The "recursive" argument must be of type boolean.' +
received
}
);
});
+1 -3
View File
@@ -363,9 +363,7 @@ async function getHandle(dest) {
async () => mkdir(dir, { recursive }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "recursive" argument must be of type boolean. ' +
`Received type ${typeof recursive}`
name: 'TypeError'
}
);
});
+6 -10
View File
@@ -15,8 +15,8 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "buffer" argument must be one of type Buffer, TypedArray, ' +
'or DataView. Received type number'
message: 'The "buffer" argument must be an instance of Buffer, ' +
'TypedArray, or DataView. Received type number (4)'
}
);
@@ -30,9 +30,7 @@ assert.throws(
common.mustNotCall());
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof value}`
name: 'TypeError'
});
});
@@ -84,8 +82,8 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "buffer" argument must be one of type Buffer, TypedArray, ' +
'or DataView. Received type number'
message: 'The "buffer" argument must be an instance of Buffer, ' +
'TypedArray, or DataView. Received type number (4)'
}
);
@@ -98,9 +96,7 @@ assert.throws(
0);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof value}`
name: 'TypeError'
});
});
+1 -1
View File
@@ -83,7 +83,7 @@ assert.throws(
assert.throws(
() => fs.read(null, Buffer.alloc(1), 0, 1, 0),
{
message: 'The "fd" argument must be of type number. Received type object',
message: 'The "fd" argument must be of type number. Received null',
code: 'ERR_INVALID_ARG_TYPE',
}
);
+2 -2
View File
@@ -60,8 +60,8 @@ common.expectsError(
() => { fs.readFile(() => {}, common.mustNotCall()); },
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "path" argument must be one of type string, Buffer, or URL.' +
' Received type function',
message: 'The "path" argument must be of type string or an instance of ' +
'Buffer or URL. Received type function ([Function (anonymous)])',
type: TypeError
}
);
+6 -5
View File
@@ -5,13 +5,14 @@ const assert = require('assert');
const fs = require('fs');
[false, 1, [], {}, null, undefined].forEach((input) => {
const type = `of type string, Buffer, or URL. Received type ${typeof input}`;
const type = 'of type string or an instance of Buffer or URL.' +
common.invalidArgTypeHelper(input);
assert.throws(
() => fs.rename(input, 'does-not-exist', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "oldPath" argument must be one ${type}`
message: `The "oldPath" argument must be ${type}`
}
);
assert.throws(
@@ -19,7 +20,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "newPath" argument must be one ${type}`
message: `The "newPath" argument must be ${type}`
}
);
assert.throws(
@@ -27,7 +28,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "oldPath" argument must be one ${type}`
message: `The "oldPath" argument must be ${type}`
}
);
assert.throws(
@@ -35,7 +36,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: `The "newPath" argument must be one ${type}`
message: `The "newPath" argument must be ${type}`
}
);
});
+1 -3
View File
@@ -116,9 +116,7 @@ fs.stat(__filename, common.mustCall(function(err, s) {
() => fs[fnName](input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof input}`
name: 'TypeError'
}
);
});
+1 -3
View File
@@ -74,13 +74,11 @@ fs.symlink(linkData, linkPath, common.mustCall(function(err) {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "target" argument must be one of type string, Buffer, or ' +
`URL. Received type ${typeof input}`
message: /target|path/
};
assert.throws(() => fs.symlink(input, '', common.mustNotCall()), errObj);
assert.throws(() => fs.symlinkSync(input, ''), errObj);
errObj.message = errObj.message.replace('target', 'path');
assert.throws(() => fs.symlink('', input, common.mustNotCall()), errObj);
assert.throws(() => fs.symlinkSync('', input), errObj);
});
+7 -8
View File
@@ -179,13 +179,13 @@ function testFtruncate(cb) {
process.on('beforeExit', () => fs.closeSync(fd));
['', false, null, {}, []].forEach((input) => {
const received = common.invalidArgTypeHelper(input);
assert.throws(
() => fs.truncate(file5, input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "len" argument must be of type number. ' +
`Received type ${typeof input}`
message: `The "len" argument must be of type number.${received}`
}
);
@@ -194,8 +194,7 @@ function testFtruncate(cb) {
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "len" argument must be of type number. ' +
`Received type ${typeof input}`
message: `The "len" argument must be of type number.${received}`
}
);
});
@@ -268,8 +267,8 @@ function testFtruncate(cb) {
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "len" argument must be of type number. ' +
`Received type ${typeof input}`
message: 'The "len" argument must be of type number.' +
common.invalidArgTypeHelper(input)
}
);
});
@@ -281,8 +280,8 @@ function testFtruncate(cb) {
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof input}`
message: 'The "fd" argument must be of type number.' +
common.invalidArgTypeHelper(input)
}
);
});
+1 -3
View File
@@ -89,9 +89,7 @@ for (const testCase of cases) {
() => fs.watch(input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "filename" argument must be one of type string, Buffer, ' +
`or URL. Received type ${typeof input}`
type: TypeError
}
);
});
@@ -22,8 +22,8 @@ server.listen(0, common.mustCall(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "method" argument must be of type string. ' +
`Received type ${typeof method}`
message: 'The "method" argument must be of type string.' +
common.invalidArgTypeHelper(method)
});
});
@@ -52,8 +52,9 @@ server.listen(0, baseOptions.host, common.mustCall(function() {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.agent" property must be one of type Agent-like' +
` Object, undefined, or false. Received type ${typeof agent}`
message: 'The "options.agent" property must be one of Agent-like ' +
'Object, undefined, or false.' +
common.invalidArgTypeHelper(agent)
}
);
});
@@ -8,14 +8,15 @@ const http = require('http');
const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()];
vals.forEach((v) => {
const received = common.invalidArgTypeHelper(v);
common.expectsError(
() => http.request({ hostname: v }),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.hostname" property must be one of ' +
'type string, undefined, or null. ' +
`Received type ${typeof v}`
message: 'The "options.hostname" property must be of ' +
'type string or one of undefined or null.' +
received
}
);
@@ -24,9 +25,9 @@ vals.forEach((v) => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.host" property must be one of ' +
'type string, undefined, or null. ' +
`Received type ${typeof v}`
message: 'The "options.host" property must be of ' +
'type string or one of undefined or null.' +
received
}
);
});
+4 -4
View File
@@ -72,7 +72,7 @@ const s = http.createServer(common.mustCall((req, res) => {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "name" argument must be of type string. ' +
'Received type undefined'
'Received undefined'
}
);
common.expectsError(
@@ -81,7 +81,7 @@ const s = http.createServer(common.mustCall((req, res) => {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "name" argument must be of type string. ' +
'Received type undefined'
'Received undefined'
}
);
@@ -124,8 +124,8 @@ const s = http.createServer(common.mustCall((req, res) => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "name" argument must be of type string. ' +
`Received type ${typeof val}`
message: 'The "name" argument must be of type string.' +
common.invalidArgTypeHelper(val)
}
);
});
+4 -4
View File
@@ -79,8 +79,8 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The first argument must be one of type string or Buffer. ' +
'Received type undefined'
message: 'The first argument must be of type string or an instance of ' +
'Buffer. Received undefined'
});
common.expectsError(() => {
@@ -89,8 +89,8 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The first argument must be one of type string or Buffer. ' +
'Received type number'
message: 'The first argument must be of type string or an instance of ' +
'Buffer. Received type number (1)'
});
// addTrailers()
@@ -48,8 +48,8 @@ server.listen(0, common.mustCall(() => {
{
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "id" argument must be of type number. Received type ' +
typeof value
message: 'The "id" argument must be of type number.' +
common.invalidArgTypeHelper(value)
}
);
});
@@ -59,7 +59,7 @@ server.listen(0, common.mustCall(function() {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "method" argument must be of type string. ' +
'Received type boolean'
'Received type boolean (true)'
}
);
@@ -48,7 +48,7 @@ server.listen(0, common.mustCall(function() {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "name" argument must be of type string. Received ' +
'type undefined'
'undefined'
}
);
});
@@ -86,7 +86,7 @@ server.listen(0, common.mustCall(function() {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "name" argument must be of type string. Received type ' +
message: 'The "name" argument must be of type string. Received ' +
'undefined'
}
);
@@ -44,7 +44,7 @@ server.listen(0, common.mustCall(() => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "name" argument must be of type string. Received type ' +
message: 'The "name" argument must be of type string. Received ' +
'undefined'
}
);
@@ -15,8 +15,8 @@ invalidOptions.forEach((invalidOption) => {
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type Object. Received ' +
`type ${typeof invalidOption}`
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(invalidOption)
}
);
});
@@ -28,8 +28,8 @@ invalidOptions.forEach((invalidSettingsOption) => {
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.settings" property must be of type Object. ' +
`Received type ${typeof invalidSettingsOption}`
message: 'The "options.settings" property must be of type object.' +
common.invalidArgTypeHelper(invalidSettingsOption)
}
);
});
@@ -15,8 +15,8 @@ invalidOptions.forEach((invalidOption) => {
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type Object. Received ' +
`type ${typeof invalidOption}`
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(invalidOption)
}
);
});
@@ -28,8 +28,8 @@ invalidOptions.forEach((invalidSettingsOption) => {
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.settings" property must be of type Object. ' +
`Received type ${typeof invalidSettingsOption}`
message: 'The "options.settings" property must be of type object.' +
common.invalidArgTypeHelper(invalidSettingsOption)
}
);
});
@@ -107,8 +107,8 @@ http2.getPackedSettings({ enablePush: false });
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message:
'The "buf" argument must be one of type Buffer, TypedArray, or ' +
`DataView. Received type ${typeof input}`
'The "buf" argument must be an instance of Buffer, TypedArray, or ' +
`DataView.${common.invalidArgTypeHelper(input)}`
});
});
@@ -14,7 +14,7 @@ server.on('stream', common.mustCall((stream) => {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "code" argument must be of type number. ' +
'Received type string'
"Received type string ('string')"
}
);
stream.respond();
+4 -2
View File
@@ -35,7 +35,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "test" argument must be of type Object. Received type string'
message: 'The "test" argument must be of type object. Received ' +
"type string ('foo')"
});
common.expectsError(
@@ -43,7 +44,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "test" argument must be of type Date. Received type string'
message: 'The "test" argument must be an instance of Date. Received type ' +
"string ('foo')"
});
assertIsObject({}, 'test');
+3 -2
View File
@@ -88,8 +88,9 @@ server.listen(0, common.mustCall(() => {
{
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "payload" argument must be one of type Buffer, ' +
`TypedArray, or DataView. Received type ${typeof payload}`
message: 'The "payload" argument must be an instance of Buffer, ' +
'TypedArray, or DataView.' +
common.invalidArgTypeHelper(payload)
}
)
);
@@ -42,9 +42,8 @@ server.on('stream', common.mustCall((stream) => {
{
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "fd" argument must be one of type number or FileHandle.' +
' Received type ' +
typeof types[type]
message: 'The "fd" argument must be of type number or an instance of' +
` FileHandle.${common.invalidArgTypeHelper(types[type])}`
}
);
});
@@ -19,13 +19,14 @@ server.on('stream', common.mustCall((stream) => {
const session = stream.session;
types.forEach((input) => {
const received = common.invalidArgTypeHelper(input);
common.expectsError(
() => session.goaway(input),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "code" argument must be of type number. Received type ' +
typeof input
message: 'The "code" argument must be of type number.' +
received
}
);
common.expectsError(
@@ -33,8 +34,8 @@ server.on('stream', common.mustCall((stream) => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "lastStreamID" argument must be of type number. ' +
`Received type ${typeof input}`
message: 'The "lastStreamID" argument must be of type number.' +
received
}
);
common.expectsError(
@@ -42,8 +43,8 @@ server.on('stream', common.mustCall((stream) => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "opaqueData" argument must be one of type Buffer, ' +
`TypedArray, or DataView. Received type ${typeof input}`
message: 'The "opaqueData" argument must be an instance of Buffer, ' +
`TypedArray, or DataView.${received}`
}
);
});
+2 -1
View File
@@ -21,7 +21,8 @@ server.on('stream', common.mustCall((stream) => {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message:
'The "msecs" argument must be of type number. Received type string'
'The "msecs" argument must be of type number. Received type string' +
" ('100')"
}
);
common.expectsError(
+7 -6
View File
@@ -26,12 +26,13 @@ const {
[],
[{}]
].forEach((input) => {
common.expectsError(() => assertIsObject(input, 'foo', 'Object'),
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "foo" argument must be of type Object. ' +
`Received type ${typeof input}`
});
common.expectsError(
() => assertIsObject(input, 'foo', 'Object'),
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "foo" argument must be of type object.' +
common.invalidArgTypeHelper(input)
});
});
assertWithinRange('foo', 1, 0, 2);
@@ -75,21 +75,22 @@ const caArrDataView = toDataView(caCert);
[true, certDataView],
[true, false],
[true, false],
[{ pem: keyBuff }, false, 'pem'],
[{ pem: keyBuff }, false],
[1, false],
[[keyBuff, true], [certBuff, certBuff2], 1],
[[true, keyStr2], [certStr, certStr2], 0],
[[true, false], [certBuff, certBuff2], 0],
[true, [certBuff, certBuff2]]
].forEach(([key, cert, index]) => {
const type = typeof (index === undefined ? key : key[index]);
const val = index === undefined ? key : key[index];
assert.throws(() => {
https.createServer({ key, cert });
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options.key" property must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
message: 'The "options.key" property must be of type string or an ' +
'instance of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(val)
});
});
@@ -100,21 +101,22 @@ const caArrDataView = toDataView(caCert);
[keyDataView, true],
[true, true],
[false, true],
[false, { pem: keyBuff }, 'pem'],
[false, { pem: keyBuff }],
[false, 1],
[[keyBuff, keyBuff2], [true, certBuff2], 0],
[[keyStr, keyStr2], [certStr, true], 1],
[[keyStr, keyStr2], [true, false], 0],
[[keyStr, keyStr2], true],
].forEach(([key, cert, index]) => {
const type = typeof (index === undefined ? cert : cert[index]);
const val = index === undefined ? cert : cert[index];
assert.throws(() => {
https.createServer({ key, cert });
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options.cert" property must be one of type string, Buffer,' +
` TypedArray, or DataView. Received type ${type}`
message: 'The "options.cert" property must be of type string or an ' +
'instance of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(val)
});
});
@@ -141,13 +143,14 @@ const caArrDataView = toDataView(caCert);
[keyBuff, certBuff, true],
[keyBuff, certBuff, [caCert, true], 1]
].forEach(([key, cert, ca, index]) => {
const type = typeof (index ? ca[index] : ca);
const val = index === undefined ? ca : ca[index];
assert.throws(() => {
https.createServer({ key, cert, ca });
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options.ca" property must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
message: 'The "options.ca" property must be of type string or an instance' +
' of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(val)
});
});
+2 -2
View File
@@ -46,8 +46,8 @@ common.expectsError(
{
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "source" argument must be one of type Buffer ' +
'or Uint8Array. Received type object'
message: 'The "source" argument must be an instance of Buffer ' +
'or Uint8Array. Received null'
}
);
@@ -1,18 +1,18 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const ModuleMap = require('internal/modules/esm/module_map');
// ModuleMap.get, ModuleMap.has and ModuleMap.set should only accept string
// values as url argument.
{
const errorReg = common.expectsError({
const errorObj = {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
name: 'TypeError',
message: /^The "url" argument must be of type string/
}, 12);
};
const moduleMap = new ModuleMap();
@@ -22,23 +22,21 @@ const ModuleMap = require('internal/modules/esm/module_map');
const job = undefined;
[{}, [], true, 1].forEach((value) => {
assert.throws(() => moduleMap.get(value), errorReg);
assert.throws(() => moduleMap.has(value), errorReg);
assert.throws(() => moduleMap.set(value, job), errorReg);
assert.throws(() => moduleMap.get(value), errorObj);
assert.throws(() => moduleMap.has(value), errorObj);
assert.throws(() => moduleMap.set(value, job), errorObj);
});
}
// ModuleMap.set, job argument should only accept ModuleJob values.
{
const errorReg = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "job" argument must be of type ModuleJob/
}, 4);
const moduleMap = new ModuleMap();
[{}, [], true, 1].forEach((value) => {
assert.throws(() => moduleMap.set('', value), errorReg);
assert.throws(() => moduleMap.set('', value), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "job" argument must be an instance of ModuleJob/
});
});
}
+1 -1
View File
@@ -60,7 +60,7 @@ assert.throws(
}
);
const re = /^The "id" argument must be of type string\. Received type \w+$/;
const re = /^The "id" argument must be of type string\. Received /;
[1, false, null, undefined, {}].forEach((value) => {
common.expectsError(
() => { require(value); },
+2 -2
View File
@@ -27,7 +27,7 @@ common.expectsError(() => socket.write(null),
socket.write(value, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "chunk" argument must be one of type string or Buffer. ' +
`Received type ${typeof value}`
message: 'The "chunk" argument must be of type string or an instance of ' +
`Buffer.${common.invalidArgTypeHelper(value)}`
}));
});
+2 -2
View File
@@ -220,8 +220,8 @@ function checkFormat(path, testCases) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "pathObject" argument must be of type Object. ' +
`Received type ${typeof pathObject}`
message: 'The "pathObject" argument must be of type object.' +
common.invalidArgTypeHelper(pathObject)
});
});
}
+1 -2
View File
@@ -65,8 +65,7 @@ const {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "fn" argument must be of type ' +
`Function. Received type ${typeof input}`
message: /The "fn" argument must be of type function/
});
});
}
+2 -2
View File
@@ -48,8 +48,8 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be of type Object. ' +
`Received type ${typeof input}`
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(input)
});
});
+6 -6
View File
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const result = process.cpuUsage();
@@ -39,7 +39,7 @@ assert.throws(
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "prevValue" argument must be of type object. ' +
'Received type number'
'Received type number (1)'
}
);
@@ -54,8 +54,8 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "prevValue.user" property must be of type number. ' +
`Received type ${typeof value.user}`
message: 'The "prevValue.user" property must be of type number.' +
common.invalidArgTypeHelper(value.user)
}
);
});
@@ -69,8 +69,8 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "prevValue.system" property must be of type number. ' +
`Received type ${typeof value.system}`
message: 'The "prevValue.system" property must be of type number.' +
common.invalidArgTypeHelper(value.system)
}
);
});
+1 -1
View File
@@ -19,7 +19,7 @@ assert.throws(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "id" argument must be one of type number or string. ' +
'Received type object'
'Received an instance of Object'
});
assert.throws(() => {
@@ -6,8 +6,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "fn" argument must be one of type Function or null. ' +
'Received type number'
message: 'The "fn" argument must be of type function or null. ' +
'Received type number (42)'
}
);
+2 -1
View File
@@ -38,7 +38,8 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "time" argument must be of type Array. Received type number'
message: 'The "time" argument must be an instance of Array. Received type ' +
'number (1)'
});
common.expectsError(() => {
process.hrtime([]);
+4 -4
View File
@@ -20,8 +20,8 @@ if (!common.isMainThread)
name: 'TypeError',
message:
'The "user" argument must be ' +
'one of type number or string. ' +
`Received type ${typeof val}`
'one of type number or string.' +
common.invalidArgTypeHelper(val)
}
);
});
@@ -36,8 +36,8 @@ if (!common.isMainThread)
name: 'TypeError',
message:
'The "extraGroup" argument must be ' +
'one of type number or string. ' +
`Received type ${typeof val}`
'one of type number or string.' +
common.invalidArgTypeHelper(val)
}
);
});
+2 -2
View File
@@ -42,8 +42,8 @@ const assert = require('assert');
assert.throws(() => process.kill(val), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "pid" argument must be of type number. ' +
`Received type ${typeof val}`
message: 'The "pid" argument must be of type number.' +
common.invalidArgTypeHelper(val)
});
});
+4 -4
View File
@@ -17,8 +17,8 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "groups" argument must be of type Array. ' +
'Received type undefined'
message: 'The "groups" argument must be an instance of Array. ' +
'Received undefined'
}
);
@@ -43,8 +43,8 @@ assert.throws(
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "groups[0]" argument must be ' +
'one of type number or string. ' +
`Received type ${typeof val}`
'one of type number or string.' +
common.invalidArgTypeHelper(val)
}
);
});
+1 -1
View File
@@ -41,7 +41,7 @@ assert.throws(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "id" argument must be one of type ' +
'number or string. Received type object'
'number or string. Received an instance of Object'
});
assert.throws(() => {
+4 -3
View File
@@ -38,20 +38,21 @@ assert.strictEqual(require.resolve('path'), 'path');
require(fixtures.path('require-resolve.js'));
require(fixtures.path('resolve-paths', 'default', 'verify-paths.js'));
const re = /^The "request" argument must be of type string\. Received type \w+$/;
[1, false, null, undefined, {}].forEach((value) => {
const message = 'The "request" argument must be of type string.' +
common.invalidArgTypeHelper(value);
common.expectsError(
() => { require.resolve(value); },
{
code: 'ERR_INVALID_ARG_TYPE',
message: re
message
});
common.expectsError(
() => { require.resolve.paths(value); },
{
code: 'ERR_INVALID_ARG_TYPE',
message: re
message
});
});
+2 -2
View File
@@ -196,8 +196,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buf" argument must be one of type Buffer, TypedArray,' +
' or DataView. Received type object'
message: 'The "buf" argument must be an instance of Buffer, TypedArray,' +
' or DataView. Received null'
}
);
+4 -4
View File
@@ -13,7 +13,7 @@ common.expectsError(
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.ciphers" property must be of type string.' +
' Received type number'
' Received type number (1)'
});
common.expectsError(
@@ -22,7 +22,7 @@ common.expectsError(
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.ciphers" property must be of type string.' +
' Received type number'
' Received type number (1)'
});
common.expectsError(
@@ -54,8 +54,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.handshakeTimeout" property must ' +
'be of type number. Received type string'
message: 'The "options.handshakeTimeout" property must be of type number.' +
" Received type string ('abcd')"
}
);
@@ -10,5 +10,5 @@ const tls = require('tls');
common.expectsError(
() => { tls.createSecureContext({ clientCertEngine: 0 }); },
{ code: 'ERR_INVALID_ARG_TYPE',
message: / Received type number$/ });
message: / Received type number \(0\)/ });
}
Loaded 100 of 127 files, more files were not shown because too many files have changed in this diff. Show more