errors: update error name

This updates all Node.js errors by removing the `code` being part
of the `name` property. Instead, the name is just changed once on
instantiation, the stack is accessed to create the stack as expected
and then the `name` property is set back to it's original form.

PR-URL: https://github.com/nodejs/node/pull/26738
Fixes: https://github.com/nodejs/node/issues/26669
Fixes: https://github.com/nodejs/node/issues/20253
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Ruben Bridgewater 2019-03-16 12:09:14 +01:00
parent c757cb1b98
commit 1ed3c54ecb
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
71 changed files with 283 additions and 284 deletions

View File

@ -388,12 +388,25 @@ class AssertionError extends Error {
}
this.generatedMessage = !message;
this.name = 'AssertionError [ERR_ASSERTION]';
Object.defineProperty(this, 'name', {
value: 'AssertionError [ERR_ASSERTION]',
enumerable: false,
writable: true,
configurable: true
});
this.code = 'ERR_ASSERTION';
this.actual = actual;
this.expected = expected;
this.operator = operator;
Error.captureStackTrace(this, stackStartFn);
// Create error message including the error code in the name.
this.stack;
// Reset the name.
this.name = 'AssertionError';
}
toString() {
return `${this.name} [${this.code}]: ${this.message}`;
}
[inspect.custom](recurseTimes, ctx) {

View File

@ -18,6 +18,8 @@ const codes = {};
const { kMaxLength } = internalBinding('buffer');
const { defineProperty } = Object;
let useOriginalName = false;
// Lazily loaded
let util;
let assert;
@ -74,19 +76,7 @@ class SystemError extends Error {
value: key,
writable: true
});
}
get name() {
return `SystemError [${this[kCode]}]`;
}
set name(value) {
defineProperty(this, 'name', {
configurable: true,
enumerable: true,
value,
writable: true
});
addCodeToName(this, 'SystemError', key);
}
get code() {
@ -141,6 +131,10 @@ class SystemError extends Error {
this[kInfo].dest = val ?
lazyBuffer().from(val.toString()) : undefined;
}
toString() {
return `${this.name} [${this.code}]: ${this.message}`;
}
}
function makeSystemErrorWithCode(key) {
@ -151,8 +145,6 @@ function makeSystemErrorWithCode(key) {
};
}
let useOriginalName = false;
function makeNodeErrorWithCode(Base, key) {
return class NodeError extends Base {
constructor(...args) {
@ -164,22 +156,7 @@ function makeNodeErrorWithCode(Base, key) {
writable: true,
configurable: true
});
}
get name() {
if (useOriginalName) {
return super.name;
}
return `${super.name} [${key}]`;
}
set name(value) {
defineProperty(this, 'name', {
configurable: true,
enumerable: true,
value,
writable: true
});
addCodeToName(this, super.name, key);
}
get code() {
@ -194,9 +171,35 @@ function makeNodeErrorWithCode(Base, key) {
writable: true
});
}
toString() {
return `${this.name} [${key}]: ${this.message}`;
}
};
}
function addCodeToName(err, name, code) {
if (useOriginalName) {
return;
}
// Add the error code to the name to include it in the stack trace.
err.name = `${name} [${code}]`;
// Access the stack to generate the error message including the error code
// from the name.
err.stack;
// Reset the name to the actual name.
if (name === 'SystemError') {
defineProperty(err, 'name', {
value: name,
enumerable: false,
writable: true,
configurable: true
});
} else {
delete err.name;
}
}
// Utility function for registering the error codes. Only used here. Exported
// *only* to allow for testing.
function E(sym, val, def, ...otherClasses) {

View File

@ -498,6 +498,12 @@ class NghttpError extends Error {
this.code = 'ERR_HTTP2_ERROR';
this.name = 'Error [ERR_HTTP2_ERROR]';
this.errno = ret;
this.stack;
delete this.name;
}
toString() {
return `${this.name} [${this.code}]: ${this.message}`;
}
}

View File

@ -13,7 +13,7 @@ const promises = [];
const rejectingFn = async () => assert.fail();
const errObj = {
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: 'Failed'
};
// `assert.rejects` accepts a function or a promise as first argument.
@ -38,7 +38,7 @@ const promises = [];
promise = assert.rejects(() => {}, common.mustNotCall());
promises.push(assert.rejects(promise, {
name: 'TypeError [ERR_INVALID_RETURN_VALUE]',
name: 'TypeError',
code: 'ERR_INVALID_RETURN_VALUE',
message: 'Expected instance of Promise to be returned ' +
'from the "promiseFn" function but got type undefined.'
@ -75,7 +75,7 @@ promises.push(assert.rejects(
message: 'Expected instance of Promise to be returned ' +
'from the "promiseFn" function but got instance of Map.',
code: 'ERR_INVALID_RETURN_VALUE',
name: 'TypeError [ERR_INVALID_RETURN_VALUE]'
name: 'TypeError'
}));
promises.push(assert.doesNotReject(async () => {}));
promises.push(assert.doesNotReject(Promise.resolve()));

View File

@ -778,7 +778,7 @@ assert.throws(
assert.throws(
() => assert.notDeepStrictEqual(new Date(2000, 3, 14), new Date(2000, 3, 14)),
{
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: 'Expected "actual" not to be strictly deep-equal to: ' +
util.inspect(new Date(2000, 3, 14))
}
@ -790,35 +790,35 @@ assert.throws(
() => assert.deepStrictEqual(/ab/, /a/),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${defaultMsgStartFull}\n\n+ /ab/\n- /a/`
});
assert.throws(
() => assert.deepStrictEqual(/a/g, /a/),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${defaultMsgStartFull}\n\n+ /a/g\n- /a/`
});
assert.throws(
() => assert.deepStrictEqual(/a/i, /a/),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${defaultMsgStartFull}\n\n+ /a/i\n- /a/`
});
assert.throws(
() => assert.deepStrictEqual(/a/m, /a/),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${defaultMsgStartFull}\n\n+ /a/m\n- /a/`
});
assert.throws(
() => assert.deepStrictEqual(/a/igm, /a/im),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${defaultMsgStartFull}\n\n+ /a/gim\n- /a/im\n ^`
});
@ -844,14 +844,14 @@ assert.deepStrictEqual({ a: 4, b: '2' }, { a: 4, b: '2' });
assert.throws(() => assert.deepStrictEqual([4], ['4']),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${defaultMsgStartFull}\n\n [\n+ 4\n- '4'\n ]`
});
assert.throws(
() => assert.deepStrictEqual({ a: 4 }, { a: 4, b: true }),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${defaultMsgStartFull}\n\n ` +
'{\n a: 4,\n- b: true\n }'
});
@ -859,7 +859,7 @@ assert.throws(
() => assert.deepStrictEqual(['a'], { 0: 'a' }),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${defaultMsgStartFull}\n\n` +
"+ [\n+ 'a'\n+ ]\n- {\n- '0': 'a'\n- }"
});
@ -953,7 +953,7 @@ assert.deepStrictEqual(obj1, obj2);
() => assert.deepStrictEqual(a, b),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: /\.\.\./g
}
);
@ -977,7 +977,7 @@ assert.throws(
() => assert.deepStrictEqual([1, 2, 3], [1, 2]),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${defaultMsgStartFull}\n\n` +
' [\n' +
' 1,\n' +
@ -1063,7 +1063,7 @@ assert.throws(
() => assert.deepStrictEqual(a, b),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: /a: \[Getter: 5]\n- a: \[Getter: 6]\n /
}
);

View File

@ -15,7 +15,7 @@ assert.throws(() => {
assert.fail('first', 'second');
}, {
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: '\'first\' != \'second\'',
operator: '!=',
actual: 'first',
@ -28,7 +28,7 @@ assert.throws(() => {
assert.fail('ignored', 'ignored', 'another custom message');
}, {
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: 'another custom message',
operator: 'fail',
actual: 'ignored',
@ -49,7 +49,7 @@ assert.throws(() => {
assert.fail('first', 'second', undefined, 'operator');
}, {
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: '\'first\' operator \'second\'',
operator: 'operator',
actual: 'first',

View File

@ -8,7 +8,7 @@ assert.throws(
() => { assert.fail(); },
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: 'Failed',
operator: 'fail',
actual: undefined,
@ -22,7 +22,7 @@ assert.throws(() => {
assert.fail('custom message');
}, {
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: 'custom message',
operator: 'fail',
actual: undefined,

View File

@ -9,7 +9,7 @@ const { path } = require('../common/fixtures');
assert.throws(
() => require(path('assert-first-line')),
{
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: "The expression evaluated to a falsy value:\n\n ässört.ok('')\n"
}
);
@ -17,7 +17,7 @@ assert.throws(
assert.throws(
() => require(path('assert-long-line')),
{
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: "The expression evaluated to a falsy value:\n\n assert.ok('')\n"
}
);

View File

@ -73,7 +73,7 @@ assert.throws(
() => a.notStrictEqual(2, 2),
{
message: 'Expected "actual" to be strictly unequal to: 2',
name: 'AssertionError [ERR_ASSERTION]'
name: 'AssertionError'
}
);
@ -82,7 +82,7 @@ assert.throws(
{
message: 'Expected "actual" to be strictly unequal to: ' +
`'${'a '.repeat(30)}'`,
name: 'AssertionError [ERR_ASSERTION]'
name: 'AssertionError'
}
);
@ -141,7 +141,7 @@ assert.throws(() => thrower(TypeError));
assert.throws(
() => a.doesNotThrow(() => thrower(Error), 'user message'),
{
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
code: 'ERR_ASSERTION',
operator: 'doesNotThrow',
message: 'Got unwanted exception: user message\n' +
@ -400,7 +400,7 @@ assert.throws(() => {
() => new assert.AssertionError(input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "options" argument must be of type Object. ' +
`Received type ${typeof input}`
});
@ -411,7 +411,7 @@ assert.throws(
() => assert.strictEqual(new Error('foo'), new Error('foobar')),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: 'Expected "actual" to be reference-equal to "expected":\n' +
'+ actual - expected\n\n' +
'+ [Error: foo]\n- [Error: foobar]'
@ -438,7 +438,7 @@ assert.throws(
() => assert(...[]),
{
message: 'No value argument passed to `assert.ok()`',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
generatedMessage: true
}
);
@ -446,7 +446,7 @@ assert.throws(
() => a(),
{
message: 'No value argument passed to `assert.ok()`',
name: 'AssertionError [ERR_ASSERTION]'
name: 'AssertionError'
}
);
@ -886,7 +886,7 @@ common.expectsError(
() => assert.throws(errFn, errObj),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${start}\n${actExp}\n\n` +
' Comparison {\n' +
' code: 404,\n' +
@ -903,7 +903,7 @@ common.expectsError(
() => assert.throws(errFn, errObj),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: `${start}\n${actExp}\n\n` +
' Comparison {\n' +
'+ code: 404,\n' +
@ -938,7 +938,7 @@ common.expectsError(
assert.throws(
() => assert.throws(() => { throw new TypeError('e'); }, new Error('e')),
{
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
code: 'ERR_ASSERTION',
message: `${start}\n${actExp}\n\n` +
' Comparison {\n' +
@ -951,7 +951,7 @@ common.expectsError(
assert.throws(
() => assert.throws(() => { throw new Error('foo'); }, new Error('')),
{
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
code: 'ERR_ASSERTION',
generatedMessage: true,
message: `${start}\n${actExp}\n\n` +
@ -969,7 +969,7 @@ common.expectsError(
// eslint-disable-next-line no-throw-literal
() => a.doesNotThrow(() => { throw undefined; }),
{
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
code: 'ERR_ASSERTION',
message: 'Got unwanted exception.\nActual message: "undefined"'
}
@ -1102,7 +1102,7 @@ assert.throws(
() => assert.strictEqual('test test', 'test foobar'),
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: strictEqualMessageStart +
'+ actual - expected\n\n' +
"+ 'test test'\n" +
@ -1119,7 +1119,7 @@ assert.throws(
},
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: 'Expected "actual" not to be reference-equal to "expected": {}'
}
);
@ -1131,7 +1131,7 @@ assert.throws(
},
{
code: 'ERR_ASSERTION',
name: 'AssertionError [ERR_ASSERTION]',
name: 'AssertionError',
message: 'Expected "actual" not to be reference-equal to "expected":\n\n' +
'{\n a: true\n}\n'
}

View File

@ -967,12 +967,12 @@ common.expectsError(
});
assert.throws(() => Buffer.from(), {
name: 'TypeError [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 undefined'
});
assert.throws(() => Buffer.from(null), {
name: 'TypeError [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'
});

View File

@ -42,7 +42,7 @@ assert.throws(function() {
Buffer.from(new AB());
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [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'
});
@ -65,12 +65,12 @@ assert.throws(function() {
assert.throws(() => Buffer.from(ab.buffer, 6), {
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: '"offset" is outside of buffer bounds'
});
assert.throws(() => Buffer.from(ab.buffer, 3, 6), {
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: '"length" is outside of buffer bounds'
});
}
@ -93,12 +93,12 @@ assert.throws(function() {
assert.throws(() => Buffer(ab.buffer, 6), {
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: '"offset" is outside of buffer bounds'
});
assert.throws(() => Buffer(ab.buffer, 3, 6), {
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: '"length" is outside of buffer bounds'
});
}
@ -120,7 +120,7 @@ assert.throws(function() {
Buffer.from(ab, Infinity);
}, {
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: '"offset" is outside of buffer bounds'
});
}
@ -142,7 +142,7 @@ assert.throws(function() {
Buffer.from(ab, 0, Infinity);
}, {
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: '"length" is outside of buffer bounds'
});
}

View File

@ -54,12 +54,12 @@ read(buf, 'readUIntLE', [2, 2], 0xea48);
// Error name and message
const OOR_ERROR =
{
name: 'RangeError [ERR_OUT_OF_RANGE]'
name: 'RangeError'
};
const OOB_ERROR =
{
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: 'Attempt to write outside buffer bounds'
};

View File

@ -116,7 +116,7 @@ assert.strictEqual(buffer.readDoubleLE(0), -Infinity);
() => buffer[fn](offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 and <= 0. Received ${offset}`
});
@ -126,7 +126,7 @@ assert.strictEqual(buffer.readDoubleLE(0), -Infinity);
() => Buffer.alloc(1)[fn](1),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: 'Attempt to write outside buffer bounds'
});
@ -135,7 +135,7 @@ assert.strictEqual(buffer.readDoubleLE(0), -Infinity);
() => buffer[fn](offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});

View File

@ -79,7 +79,7 @@ assert.strictEqual(buffer.readFloatLE(0), -Infinity);
() => buffer[fn](offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 and <= 0. Received ${offset}`
});
@ -89,7 +89,7 @@ assert.strictEqual(buffer.readFloatLE(0), -Infinity);
() => Buffer.alloc(1)[fn](1),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: 'Attempt to write outside buffer bounds'
});
@ -98,7 +98,7 @@ assert.strictEqual(buffer.readFloatLE(0), -Infinity);
() => buffer[fn](offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});

View File

@ -18,7 +18,7 @@ const assert = require('assert');
() => buffer[`read${fn}`](o),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
});
});
@ -27,7 +27,7 @@ const assert = require('assert');
() => buffer[`read${fn}`](offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]'
name: 'RangeError'
});
});
@ -36,7 +36,7 @@ const assert = require('assert');
() => buffer[`read${fn}`](offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});
@ -152,7 +152,7 @@ const assert = require('assert');
() => buffer[fn](0, byteLength),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "byteLength" is out of range. ' +
`It must be an integer. Received ${byteLength}`
});
@ -167,7 +167,7 @@ const assert = require('assert');
() => buffer[fn](o, i),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
});
});
@ -176,7 +176,7 @@ const assert = require('assert');
() => buffer[fn](offset, i),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 and <= ${8 - i}. Received ${offset}`
});
@ -187,7 +187,7 @@ const assert = require('assert');
() => buffer[fn](offset, i),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});

View File

@ -18,7 +18,7 @@ const assert = require('assert');
() => buffer[`read${fn}`](o),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
});
});
@ -27,7 +27,7 @@ const assert = require('assert');
() => buffer[`read${fn}`](offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]'
name: 'RangeError'
});
});
@ -36,7 +36,7 @@ const assert = require('assert');
() => buffer[`read${fn}`](offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});
@ -120,7 +120,7 @@ const assert = require('assert');
() => buffer[fn](0, byteLength),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "byteLength" is out of range. ' +
`It must be an integer. Received ${byteLength}`
});
@ -135,7 +135,7 @@ const assert = require('assert');
() => buffer[fn](o, i),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
});
});
@ -144,7 +144,7 @@ const assert = require('assert');
() => buffer[fn](offset, i),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 and <= ${8 - i}. Received ${offset}`
});
@ -155,7 +155,7 @@ const assert = require('assert');
() => buffer[fn](offset, i),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});

View File

@ -42,7 +42,7 @@ try {
// Should throw with invalid length type
const bufferInvalidTypeMsg = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: /^The "size" argument must be of type number/,
};
assert.throws(() => SlowBuffer(), bufferInvalidTypeMsg);
@ -53,7 +53,7 @@ assert.throws(() => SlowBuffer(true), bufferInvalidTypeMsg);
// Should throw with invalid length value
const bufferMaxSizeMsg = {
code: 'ERR_INVALID_OPT_VALUE',
name: 'RangeError [ERR_INVALID_OPT_VALUE]',
name: 'RangeError',
message: /^The value "[^"]*" is invalid for option "size"$/
};
assert.throws(() => SlowBuffer(NaN), bufferMaxSizeMsg);

View File

@ -98,7 +98,7 @@ assert.ok(Number.isNaN(buffer.readDoubleLE(8)));
() => small[fn](11.11, 0),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: 'Attempt to write outside buffer bounds'
});
@ -113,7 +113,7 @@ assert.ok(Number.isNaN(buffer.readDoubleLE(8)));
() => buffer[fn](23, offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 and <= 8. Received ${offset}`
});
@ -124,7 +124,7 @@ assert.ok(Number.isNaN(buffer.readDoubleLE(8)));
() => buffer[fn](42, offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});

View File

@ -80,7 +80,7 @@ assert.ok(Number.isNaN(buffer.readFloatLE(4)));
() => small[fn](11.11, 0),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
name: 'RangeError',
message: 'Attempt to write outside buffer bounds'
});
@ -96,7 +96,7 @@ assert.ok(Number.isNaN(buffer.readFloatLE(4)));
() => buffer[fn](23, offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 and <= 4. Received ${offset}`
}
@ -108,7 +108,7 @@ assert.ok(Number.isNaN(buffer.readFloatLE(4)));
() => buffer[fn](42, offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});

View File

@ -205,7 +205,7 @@ const errorOutOfBounds = common.expectsError({
() => data[fn](42, 0, byteLength),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "byteLength" is out of range. ' +
`It must be an integer. Received ${byteLength}`
});
@ -223,7 +223,7 @@ const errorOutOfBounds = common.expectsError({
data[fn](val, 0, i);
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "value" is out of range. ' +
`It must be >= ${min} and <= ${max}. Received ${val}`
});
@ -234,7 +234,7 @@ const errorOutOfBounds = common.expectsError({
() => data[fn](min, o, i),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
});
});
@ -243,7 +243,7 @@ const errorOutOfBounds = common.expectsError({
() => data[fn](min, offset, i),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 and <= ${8 - i}. Received ${offset}`
});
@ -254,7 +254,7 @@ const errorOutOfBounds = common.expectsError({
() => data[fn](max, offset, i),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});

View File

@ -162,7 +162,7 @@ const assert = require('assert');
() => data[fn](42, 0, byteLength),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "byteLength" is out of range. ' +
`It must be an integer. Received ${byteLength}`
});
@ -176,7 +176,7 @@ const assert = require('assert');
data[fn](val, 0, i);
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "value" is out of range. ' +
`It must be >= 0 and <= ${val - 1}. Received ${val}`
});
@ -186,7 +186,7 @@ const assert = require('assert');
() => data[fn](23, o, i),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
});
});
@ -195,7 +195,7 @@ const assert = require('assert');
() => data[fn](val - 1, offset, i),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 and <= ${8 - i}. Received ${offset}`
});
@ -206,7 +206,7 @@ const assert = require('assert');
() => data[fn](val - 1, offset, i),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be an integer. Received ${offset}`
});

View File

@ -39,18 +39,18 @@ n.on('message', (m) => {
// https://github.com/joyent/node/issues/2355 - JSON.stringify(undefined)
// returns "undefined" but JSON.parse() cannot parse that...
assert.throws(() => n.send(undefined), {
name: 'TypeError [ERR_MISSING_ARGS]',
name: 'TypeError',
message: 'The "message" argument must be specified',
code: 'ERR_MISSING_ARGS'
});
assert.throws(() => n.send(), {
name: 'TypeError [ERR_MISSING_ARGS]',
name: 'TypeError',
message: 'The "message" argument must be specified',
code: 'ERR_MISSING_ARGS'
});
assert.throws(() => n.send(Symbol()), {
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "message" argument must be one of type string,' +
' object, number, or boolean. Received type symbol',
code: 'ERR_INVALID_ARG_TYPE'

View File

@ -64,7 +64,7 @@ assert.throws(
() => crypto.pbkdf2('password', 'salt', 1, 20, null),
{
code: 'ERR_INVALID_CALLBACK',
name: 'TypeError [ERR_INVALID_CALLBACK]'
name: 'TypeError'
}
);
@ -72,7 +72,7 @@ assert.throws(
() => crypto.pbkdf2Sync('password', 'salt', -1, 20, 'sha1'),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "iterations" is out of range. ' +
'It must be >= 0 && < 4294967296. Received -1'
}
@ -84,7 +84,7 @@ assert.throws(
crypto.pbkdf2Sync('password', 'salt', 1, notNumber, 'sha256');
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "keylen" argument must be of type number. ' +
`Received type ${typeof notNumber}`
});
@ -97,7 +97,7 @@ assert.throws(
common.mustNotCall());
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "keylen" is out of range. It ' +
`must be an integer. Received ${input}`
});
@ -110,7 +110,7 @@ assert.throws(
common.mustNotCall());
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "keylen" is out of range. It ' +
`must be >= 0 && < 4294967296. Received ${input}`
});
@ -124,7 +124,7 @@ assert.throws(
() => crypto.pbkdf2('password', 'salt', 8, 8, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "digest" argument must be one of type string or null. ' +
'Received type undefined'
});
@ -133,7 +133,7 @@ assert.throws(
() => crypto.pbkdf2Sync('password', 'salt', 8, 8),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "digest" argument must be one of type string or null. ' +
'Received type undefined'
});
@ -145,7 +145,7 @@ assert.throws(
() => crypto.pbkdf2(input, 'salt', 8, 8, 'sha256', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "password" argument must be one of type string, ${msgPart2}`
}
);
@ -154,7 +154,7 @@ assert.throws(
() => crypto.pbkdf2('pass', input, 8, 8, 'sha256', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "salt" argument must be one of type string, ${msgPart2}`
}
);
@ -163,7 +163,7 @@ assert.throws(
() => crypto.pbkdf2Sync(input, 'salt', 8, 8, 'sha256'),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "password" argument must be one of type string, ${msgPart2}`
}
);
@ -172,7 +172,7 @@ assert.throws(
() => crypto.pbkdf2Sync('pass', input, 8, 8, 'sha256'),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "salt" argument must be one of type string, ${msgPart2}`
}
);
@ -184,7 +184,7 @@ assert.throws(
() => crypto.pbkdf2('pass', 'salt', i, 8, 'sha256', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "iterations" argument must be of type number. ${received}`
}
);
@ -193,7 +193,7 @@ assert.throws(
() => crypto.pbkdf2Sync('pass', 'salt', i, 8, 'sha256'),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "iterations" argument must be of type number. ${received}`
}
);
@ -226,7 +226,7 @@ assert.throws(
() => crypto.pbkdf2('pass', 'salt', 8, 8, 'md55', common.mustNotCall()),
{
code: 'ERR_CRYPTO_INVALID_DIGEST',
name: 'TypeError [ERR_CRYPTO_INVALID_DIGEST]',
name: 'TypeError',
message: 'Invalid digest: md55'
}
);
@ -235,7 +235,7 @@ assert.throws(
() => crypto.pbkdf2Sync('pass', 'salt', 8, 8, 'md55'),
{
code: 'ERR_CRYPTO_INVALID_DIGEST',
name: 'TypeError [ERR_CRYPTO_INVALID_DIGEST]',
name: 'TypeError',
message: 'Invalid digest: md55'
}
);

View File

@ -44,7 +44,7 @@ common.expectWarning('DeprecationWarning',
[undefined, null, false, true, {}, []].forEach((value) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "size" argument must be of type number. ' +
`Received type ${typeof value}`
};
@ -55,7 +55,7 @@ common.expectWarning('DeprecationWarning',
[-1, NaN, 2 ** 32].forEach((value) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "size" is out of range. It must be >= 0 && <= ' +
`${kMaxPossibleLength}. Received ${value}`
};
@ -199,7 +199,7 @@ common.expectWarning('DeprecationWarning',
const typeErrObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "offset" argument must be of type number. ' +
'Received type string'
};
@ -222,7 +222,7 @@ common.expectWarning('DeprecationWarning',
[NaN, kMaxPossibleLength + 1, -10, (-1 >>> 0) + 1].forEach((offsetSize) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 && <= 10. Received ${offsetSize}`
};
@ -245,7 +245,7 @@ common.expectWarning('DeprecationWarning',
const rangeErrObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "size + offset" is out of range. ' +
'It must be <= 10. Received 11'
};
@ -265,7 +265,7 @@ assert.throws(
() => crypto.randomBytes((-1 >>> 0) + 1),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "size" is out of range. ' +
`It must be >= 0 && <= ${kMaxPossibleLength}. Received 4294967296`
}

View File

@ -323,7 +323,7 @@ common.expectsError(
const type = typeof input;
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "algorithm" argument must be of type string. ' +
`Received type ${type}`
};
@ -350,7 +350,7 @@ common.expectsError(
const type = typeof input;
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "key" argument must be one of type string, Buffer, ' +
`TypedArray, DataView, or KeyObject. Received type ${type}`
};

View File

@ -25,7 +25,7 @@ const client = dgram.createSocket('udp4').bind(0, () => {
[[], 1, true].forEach((invalidInput) => {
const expectedError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "address" argument must be one of type string or falsy. ' +
`Received type ${typeof invalidInput}`
};

View File

@ -6,7 +6,7 @@ const socket = dgram.createSocket('udp4');
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "offset" argument must be of type number. Received type ' +
'undefined'
};

View File

@ -19,7 +19,7 @@ const promiseResolver = new dns.promises.Resolver();
].forEach((val) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "servers" argument must be of type Array. Received type ' +
typeof val
};
@ -59,7 +59,7 @@ const promiseResolver = new dns.promises.Resolver();
].forEach((val) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "servers[0]" argument must be of type string. ' +
`Received type ${typeof val[0]}`
};

View File

@ -81,7 +81,7 @@ assert(existing.length > 0);
dns.setServers([serv]);
},
{
name: 'TypeError [ERR_INVALID_IP_ADDRESS]',
name: 'TypeError',
code: 'ERR_INVALID_IP_ADDRESS'
}
);

View File

@ -41,6 +41,6 @@ assert.strictEqual(cycle(Function), '[Function: Function]');
{
const err = new ERR_INVALID_ARG_TYPE('object', 'Object', 42);
assert(/^TypeError \[ERR_INVALID_ARG_TYPE\]:/.test(err));
assert.strictEqual(err.name, 'TypeError [ERR_INVALID_ARG_TYPE]');
assert.strictEqual(err.name, 'TypeError');
assert.strictEqual(err.code, 'ERR_INVALID_ARG_TYPE');
}

View File

@ -6,7 +6,7 @@ const assert = require('assert');
const { E, SystemError, codes } = require('internal/errors');
assert.throws(
() => { throw new SystemError(); },
() => { new SystemError(); },
{
name: 'TypeError',
message: 'Cannot read property \'match\' of undefined'
@ -29,7 +29,7 @@ const { ERR_TEST } = codes;
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
name: 'SystemError [ERR_TEST]',
name: 'SystemError',
message: 'custom message: syscall_test returned ETEST (code message)' +
' /str => /str2',
info: ctx
@ -49,7 +49,7 @@ const { ERR_TEST } = codes;
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
name: 'SystemError [ERR_TEST]',
name: 'SystemError',
message: 'custom message: syscall_test returned ETEST (code message)' +
' /buf => /str2',
info: ctx
@ -69,7 +69,7 @@ const { ERR_TEST } = codes;
() => { throw new ERR_TEST(ctx); },
{
code: 'ERR_TEST',
name: 'SystemError [ERR_TEST]',
name: 'SystemError',
message: 'custom message: syscall_test returned ETEST (code message)' +
' /buf => /buf2',
info: ctx
@ -121,12 +121,12 @@ const { ERR_TEST } = codes;
assert.throws(
() => {
const err = new ERR_TEST(ctx);
err.name = 'SystemError [CUSTOM_ERR_TEST]';
err.name = 'Foobar';
throw err;
},
{
code: 'ERR_TEST',
name: 'SystemError [CUSTOM_ERR_TEST]',
name: 'Foobar',
message: 'custom message: syscall_test returned ERR_TEST ' +
'(Error occurred)',
info: ctx

View File

@ -150,7 +150,7 @@ if (fs.lchmod) {
[false, 1, {}, [], null, undefined].forEach((input) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "path" argument must be one of type string, Buffer, or URL.' +
` Received type ${typeof input}`
};

View File

@ -10,7 +10,7 @@ const fs = require('fs');
['', false, null, undefined, {}, []].forEach((input) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof input}`
};

View File

@ -11,7 +11,7 @@ const fs = require('fs');
[false, null, undefined, {}, [], ''].forEach((input) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "fd" argument must be of type number. Received type ' +
typeof input
};
@ -23,7 +23,7 @@ const fs = require('fs');
[false, null, undefined, {}, [], '', '123x'].forEach((input) => {
const errObj = {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError [ERR_INVALID_ARG_VALUE]',
name: 'TypeError',
message: 'The argument \'mode\' must be a 32-bit unsigned integer or an ' +
`octal string. Received ${util.inspect(input)}`
};
@ -34,7 +34,7 @@ const fs = require('fs');
[-1, 2 ** 32].forEach((input) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "fd" is out of range. It must be >= 0 && <= ' +
`2147483647. Received ${input}`
};
@ -45,7 +45,7 @@ const fs = require('fs');
[-1, 2 ** 32].forEach((input) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "mode" is out of range. It must be >= 0 && <= ' +
`4294967295. Received ${input}`
};
@ -57,7 +57,7 @@ const fs = require('fs');
[NaN, Infinity].forEach((input) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "fd" is out of range. It must be an integer. ' +
`Received ${input}`
};
@ -71,7 +71,7 @@ const fs = require('fs');
[1.5].forEach((input) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "fd" is out of range. It must be an integer. ' +
`Received ${input}`
};

View File

@ -18,7 +18,7 @@ function test(input, errObj) {
['', false, null, undefined, {}, []].forEach((input) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "fd" argument must be of type number. Received type ' +
typeof input
};
@ -28,7 +28,7 @@ function test(input, errObj) {
[Infinity, NaN].forEach((input) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "fd" is out of range. It must be an integer. ' +
`Received ${input}`
};
@ -38,7 +38,7 @@ function test(input, errObj) {
[-1, 2 ** 32].forEach((input) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "fd" is out of range. It must be ' +
`>= 0 && < 4294967296. Received ${input}`
};

View File

@ -53,7 +53,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 [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "fd" argument must be of type number. Received type ' +
typeof input
};

View File

@ -41,7 +41,7 @@ assert.throws(() => fs.lchmod(f, {}), { code: 'ERR_INVALID_CALLBACK' });
[false, null, undefined, {}, [], '', '123x'].forEach((input) => {
const errObj = {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError [ERR_INVALID_ARG_VALUE]',
name: 'TypeError',
message: 'The argument \'mode\' must be a 32-bit unsigned integer or an ' +
`octal string. Received ${util.inspect(input)}`
};
@ -53,7 +53,7 @@ assert.throws(() => fs.lchmod(f, {}), { code: 'ERR_INVALID_CALLBACK' });
[-1, 2 ** 32].forEach((input) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "mode" is out of range. It must be >= 0 && <= ' +
`4294967295. Received ${input}`
};

View File

@ -102,7 +102,7 @@ for (const extra of [[], ['r'], ['r', 0], ['r', 0, 'bad callback']]) {
fs.promises.open(i, 'r'),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
}
);
});

View File

@ -164,7 +164,7 @@ async function getHandle(dest) {
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "gid" is out of range. ' +
'It must be >= 0 && < 4294967296. Received -1'
});
@ -175,7 +175,7 @@ async function getHandle(dest) {
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "gid" is out of range. ' +
'It must be >= 0 && < 4294967296. Received -1'
});
@ -336,7 +336,7 @@ async function getHandle(dest) {
async () => mkdir(dir, { recursive }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "recursive" argument must be of type boolean. ' +
`Received type ${typeof recursive}`
}
@ -352,7 +352,7 @@ async function getHandle(dest) {
async () => mkdtemp(1),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
}
);
}

View File

@ -14,7 +14,7 @@ assert.throws(
() => fs.read(fd, expected.length, 0, 'utf-8', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "buffer" argument must be one of type Buffer, TypedArray, ' +
'or DataView. Received type number'
}
@ -30,7 +30,7 @@ assert.throws(
common.mustNotCall());
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof value}`
});
@ -45,7 +45,7 @@ assert.throws(() => {
common.mustNotCall());
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. It must be >= 0 && <= 4. ' +
'Received -1'
});
@ -59,7 +59,7 @@ assert.throws(() => {
common.mustNotCall());
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "length" is out of range. ' +
'It must be >= 0 && <= 4. Received -1'
});
@ -69,7 +69,7 @@ assert.throws(
() => fs.readSync(fd, expected.length, 0, 'utf-8'),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "buffer" argument must be one of type Buffer, TypedArray, ' +
'or DataView. Received type number'
}
@ -84,7 +84,7 @@ assert.throws(
0);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof value}`
});
@ -98,7 +98,7 @@ assert.throws(() => {
0);
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
'It must be >= 0 && <= 4. Received -1'
});
@ -111,7 +111,7 @@ assert.throws(() => {
0);
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "length" is out of range. ' +
'It must be >= 0 && <= 4. Received -1'
});

View File

@ -10,7 +10,7 @@ const fs = require('fs');
() => fs.rename(input, 'does-not-exist', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "oldPath" argument must be one ${type}`
}
);
@ -18,7 +18,7 @@ const fs = require('fs');
() => fs.rename('does-not-exist', input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "newPath" argument must be one ${type}`
}
);
@ -26,7 +26,7 @@ const fs = require('fs');
() => fs.renameSync(input, 'does-not-exist'),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "oldPath" argument must be one ${type}`
}
);
@ -34,7 +34,7 @@ const fs = require('fs');
() => fs.renameSync('does-not-exist', input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: `The "newPath" argument must be one ${type}`
}
);

View File

@ -134,7 +134,7 @@ fs.stat(__filename, common.mustCall(function(err, s) {
() => fs[fnName](input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof input}`
}
@ -147,28 +147,28 @@ fs.stat(__filename, common.mustCall(function(err, s) {
() => fs.lstat(input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
}
);
assert.throws(
() => fs.lstatSync(input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
}
);
assert.throws(
() => fs.stat(input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
}
);
assert.throws(
() => fs.statSync(input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
}
);
});

View File

@ -61,7 +61,7 @@ fs.symlink(linkData, linkPath, common.mustCall(function(err) {
[false, 1, {}, [], null, undefined].forEach((input) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "target" argument must be one of type string, Buffer, or ' +
`URL. Received type ${typeof input}`
};
@ -75,7 +75,7 @@ fs.symlink(linkData, linkPath, common.mustCall(function(err) {
const errObj = {
code: 'ERR_FS_INVALID_SYMLINK_TYPE',
name: 'Error [ERR_FS_INVALID_SYMLINK_TYPE]',
name: 'Error',
message:
'Symlink type must be one of "dir", "file", or "junction". Received "🍏"'
};

View File

@ -183,7 +183,7 @@ function testFtruncate(cb) {
() => fs.truncate(file5, input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "len" argument must be of type number. ' +
`Received type ${typeof input}`
}
@ -193,7 +193,7 @@ function testFtruncate(cb) {
() => fs.ftruncate(fd, input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "len" argument must be of type number. ' +
`Received type ${typeof input}`
}
@ -205,7 +205,7 @@ function testFtruncate(cb) {
() => fs.truncate(file5, input),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "len" is out of range. It must be ' +
`an integer. Received ${input}`
}
@ -215,7 +215,7 @@ function testFtruncate(cb) {
() => fs.ftruncate(fd, input),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "len" is out of range. It must be ' +
`an integer. Received ${input}`
}
@ -267,7 +267,7 @@ function testFtruncate(cb) {
() => fs.truncate('/foo/bar', input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "len" argument must be of type number. ' +
`Received type ${typeof input}`
}
@ -280,7 +280,7 @@ function testFtruncate(cb) {
() => fs[fnName](input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "fd" argument must be of type number. ' +
`Received type ${typeof input}`
}

View File

@ -37,7 +37,7 @@ server.once('request', common.mustCall((req, res) => {
const expectedError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
};
// Write should not accept an Array

View File

@ -33,7 +33,7 @@ server.on('session', common.mustCall((session) => {
() => session.altsvc('h2=":8000"', input),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "originOrStream" is out of ' +
`range. It must be > 0 && < 4294967296. Received ${input}`
}
@ -46,7 +46,7 @@ server.on('session', common.mustCall((session) => {
() => session.altsvc(input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
}
);
});
@ -56,7 +56,7 @@ server.on('session', common.mustCall((session) => {
() => session.altsvc(input),
{
code: 'ERR_INVALID_CHAR',
name: 'TypeError [ERR_INVALID_CHAR]',
name: 'TypeError',
message: 'Invalid character in alt'
}
);
@ -67,7 +67,7 @@ server.on('session', common.mustCall((session) => {
() => session.altsvc('clear', input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
}
);
});
@ -82,7 +82,7 @@ server.on('session', common.mustCall((session) => {
() => session.altsvc('h2=":8000', input),
{
code: 'ERR_HTTP2_ALTSVC_INVALID_ORIGIN',
name: 'TypeError [ERR_HTTP2_ALTSVC_INVALID_ORIGIN]',
name: 'TypeError',
message: 'HTTP/2 ALTSVC frames require a valid origin'
}
);
@ -96,7 +96,7 @@ server.on('session', common.mustCall((session) => {
},
{
code: 'ERR_HTTP2_ALTSVC_LENGTH',
name: 'TypeError [ERR_HTTP2_ALTSVC_LENGTH]',
name: 'TypeError',
message: 'HTTP/2 ALTSVC frames are limited to 16382 bytes'
}
);

View File

@ -27,7 +27,7 @@ server.listen(0, common.mustCall(() => {
client.on('error', common.expectsError({
code: 'ERR_HTTP2_ERROR',
type: NghttpError,
name: 'Error [ERR_HTTP2_ERROR]',
name: 'Error',
message: 'Protocol error'
}));

View File

@ -55,7 +55,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
error: {
code: 'ERR_HTTP2_ERROR',
type: NghttpError,
name: 'Error [ERR_HTTP2_ERROR]',
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
type: 'session'

View File

@ -21,7 +21,7 @@ server.listen(0, common.mustCall(() => {
assert.throws(
() => req.close(2 ** 32),
{
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "code" is out of range. It must be ' +
'>= 0 && <= 4294967295. Received 4294967296'

View File

@ -49,7 +49,7 @@ server.listen(0, common.mustCall(function() {
() => request.method = ' ',
{
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError [ERR_INVALID_ARG_VALUE]',
name: 'TypeError',
message: "The argument 'method' is invalid. Received ' '"
}
);
@ -57,7 +57,7 @@ server.listen(0, common.mustCall(function() {
() => request.method = true,
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "method" argument must be of type string. ' +
'Received type boolean'
}

View File

@ -46,7 +46,7 @@ server.listen(0, common.mustCall(function() {
() => response[fnName](),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "name" argument must be of type string. Received ' +
'type undefined'
}

View File

@ -13,7 +13,7 @@ invalidOptions.forEach((invalidOption) => {
assert.throws(
() => http2.createSecureServer(invalidOption),
{
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type Object. Received ' +
`type ${typeof invalidOption}`

View File

@ -28,7 +28,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
error: {
code: 'ERR_HTTP2_ERROR',
type: NghttpError,
name: 'Error [ERR_HTTP2_ERROR]',
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
type: 'stream'

View File

@ -46,7 +46,7 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
() => session.origin(input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
name: 'TypeError'
}
);
});
@ -56,7 +56,7 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
() => session.origin(input),
{
code: 'ERR_HTTP2_INVALID_ORIGIN',
name: 'TypeError [ERR_HTTP2_INVALID_ORIGIN]'
name: 'TypeError'
}
);
});
@ -66,7 +66,7 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
() => session.origin(input),
{
code: 'ERR_INVALID_URL',
name: 'TypeError [ERR_INVALID_URL]'
name: 'TypeError'
}
);
});
@ -75,7 +75,7 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
() => session.origin(longInput),
{
code: 'ERR_HTTP2_ORIGIN_LENGTH',
name: 'TypeError [ERR_HTTP2_ORIGIN_LENGTH]'
name: 'TypeError'
}
);
}));

View File

@ -29,7 +29,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
error: {
code: 'ERR_HTTP2_ERROR',
type: NghttpError,
name: 'Error [ERR_HTTP2_ERROR]',
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
type: 'stream'

View File

@ -36,7 +36,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
error: {
code: 'ERR_HTTP2_ERROR',
type: NghttpError,
name: 'Error [ERR_HTTP2_ERROR]',
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
type: 'stream'

View File

@ -31,7 +31,7 @@ server.on('stream', common.mustCall((stream, headers) => {
() => stream.pushStream({ 'connection': 'test' }, {}, () => {}),
{
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
name: 'TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]',
name: 'TypeError',
message: 'HTTP/1 Connection specific headers are forbidden: "connection"'
}
);

View File

@ -53,7 +53,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
error: {
code: 'ERR_HTTP2_ERROR',
type: NghttpError,
name: 'Error [ERR_HTTP2_ERROR]',
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
type: 'stream'

View File

@ -283,7 +283,7 @@ const {
].forEach((name) => {
common.expectsError(() => mapToHeaders({ [name]: 'abc' }), {
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
name: 'TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]',
name: 'TypeError',
message: 'HTTP/1 Connection specific headers are forbidden: ' +
`"${name.toLowerCase()}"`
});
@ -291,7 +291,7 @@ const {
common.expectsError(() => mapToHeaders({ [HTTP2_HEADER_TE]: ['abc'] }), {
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
name: 'TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]',
name: 'TypeError',
message: 'HTTP/1 Connection specific headers are forbidden: ' +
`"${HTTP2_HEADER_TE}"`
});
@ -299,7 +299,7 @@ common.expectsError(() => mapToHeaders({ [HTTP2_HEADER_TE]: ['abc'] }), {
common.expectsError(
() => mapToHeaders({ [HTTP2_HEADER_TE]: ['abc', 'trailers'] }), {
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
name: 'TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]',
name: 'TypeError',
message: 'HTTP/1 Connection specific headers are forbidden: ' +
`"${HTTP2_HEADER_TE}"`
});

View File

@ -87,7 +87,7 @@ const caArrDataView = toDataView(caCert);
https.createServer({ key, cert });
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "options.key" property must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
});
@ -112,7 +112,7 @@ const caArrDataView = toDataView(caCert);
https.createServer({ key, cert });
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "options.cert" property must be one of type string, Buffer,' +
` TypedArray, or DataView. Received type ${type}`
});
@ -146,7 +146,7 @@ const caArrDataView = toDataView(caCert);
https.createServer({ key, cert, ca });
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "options.ca" property must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
});

View File

@ -17,7 +17,7 @@ errors.E('TEST_ERROR_1', 'Error for testing purposes: %s',
{
const err = new errors.codes.TEST_ERROR_1('test');
assert(err instanceof Error);
assert.strictEqual(err.name, 'Error [TEST_ERROR_1]');
assert.strictEqual(err.name, 'Error');
}
{
@ -31,5 +31,5 @@ errors.E('TEST_ERROR_1', 'Error for testing purposes: %s',
errors.useOriginalName = false;
const err = new errors.codes.TEST_ERROR_1('test');
assert(err instanceof Error);
assert.strictEqual(err.name, 'Error [TEST_ERROR_1]');
assert.strictEqual(err.name, 'Error');
}

View File

@ -20,7 +20,7 @@ errors.E('TEST_ERROR_2', (a, b) => `${a} ${b}`, Error);
{
const err = new errors.codes.TEST_ERROR_1('test');
assert(err instanceof Error);
assert.strictEqual(err.name, 'Error [TEST_ERROR_1]');
assert.strictEqual(err.name, 'Error');
assert.strictEqual(err.message, 'Error for testing purposes: test');
assert.strictEqual(err.code, 'TEST_ERROR_1');
}
@ -28,7 +28,7 @@ errors.E('TEST_ERROR_2', (a, b) => `${a} ${b}`, Error);
{
const err = new errors.codes.TEST_ERROR_1.TypeError('test');
assert(err instanceof TypeError);
assert.strictEqual(err.name, 'TypeError [TEST_ERROR_1]');
assert.strictEqual(err.name, 'TypeError');
assert.strictEqual(err.message, 'Error for testing purposes: test');
assert.strictEqual(err.code, 'TEST_ERROR_1');
}
@ -36,7 +36,7 @@ errors.E('TEST_ERROR_2', (a, b) => `${a} ${b}`, Error);
{
const err = new errors.codes.TEST_ERROR_1.RangeError('test');
assert(err instanceof RangeError);
assert.strictEqual(err.name, 'RangeError [TEST_ERROR_1]');
assert.strictEqual(err.name, 'RangeError');
assert.strictEqual(err.message, 'Error for testing purposes: test');
assert.strictEqual(err.code, 'TEST_ERROR_1');
}
@ -44,7 +44,7 @@ errors.E('TEST_ERROR_2', (a, b) => `${a} ${b}`, Error);
{
const err = new errors.codes.TEST_ERROR_2('abc', 'xyz');
assert(err instanceof Error);
assert.strictEqual(err.name, 'Error [TEST_ERROR_2]');
assert.strictEqual(err.name, 'Error');
assert.strictEqual(err.message, 'abc xyz');
assert.strictEqual(err.code, 'TEST_ERROR_2');
}
@ -79,27 +79,6 @@ common.expectsError(() => {
message: 'Error for testing purposes: a'
});
common.expectsError(() => {
common.expectsError(() => {
throw new errors.codes.TEST_ERROR_1.TypeError('a');
}, { code: 'TEST_ERROR_1', type: RangeError });
}, {
code: 'ERR_ASSERTION',
message: /\+ type: \[Function: TypeError]\n- type: \[Function: RangeError]/
});
common.expectsError(() => {
common.expectsError(() => {
throw new errors.codes.TEST_ERROR_1.TypeError('a');
}, { code: 'TEST_ERROR_1',
type: TypeError,
message: /^Error for testing 2/ });
}, {
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: /\+ message: 'Error for testing purposes: a',\n- message: \/\^Error/
});
// Test that `code` property is mutable and that changing it does not change the
// name.
{
@ -113,7 +92,7 @@ common.expectsError(() => {
assert.strictEqual(myError.code, 'FHQWHGADS');
assert.strictEqual(myError.name, initialName);
assert.deepStrictEqual(Object.keys(myError), ['code']);
assert.ok(myError.name.includes('TEST_ERROR_1'));
assert.ok(!myError.name.includes('TEST_ERROR_1'));
assert.ok(!myError.name.includes('FHQWHGADS'));
}

View File

@ -48,7 +48,7 @@ function testNextTickWith(val) {
},
{
code: 'ERR_INVALID_CALLBACK',
name: 'TypeError [ERR_INVALID_CALLBACK]',
name: 'TypeError',
type: TypeError
}
);

View File

@ -37,7 +37,7 @@ assert.throws(
() => process.cpuUsage(1),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "prevValue" argument must be of type object. ' +
'Received type number'
}
@ -53,7 +53,7 @@ assert.throws(
() => process.cpuUsage(value),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "prevValue.user" property must be of type number. ' +
`Received type ${typeof value.user}`
}
@ -68,7 +68,7 @@ assert.throws(
() => process.cpuUsage(value),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "prevValue.system" property must be of type number. ' +
`Received type ${typeof value.system}`
}
@ -84,7 +84,7 @@ assert.throws(
() => process.cpuUsage(value),
{
code: 'ERR_INVALID_OPT_VALUE',
name: 'RangeError [ERR_INVALID_OPT_VALUE]',
name: 'RangeError',
message: `The value "${value.user}" is invalid ` +
'for option "prevValue.user"'
}
@ -99,7 +99,7 @@ assert.throws(
() => process.cpuUsage(value),
{
code: 'ERR_INVALID_OPT_VALUE',
name: 'RangeError [ERR_INVALID_OPT_VALUE]',
name: 'RangeError',
message: `The value "${value.system}" is invalid ` +
'for option "prevValue.system"'
}

View File

@ -17,7 +17,7 @@ if (!common.isMainThread)
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message:
'The "user" argument must be ' +
'one of type number or string. ' +
@ -33,7 +33,7 @@ if (!common.isMainThread)
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message:
'The "extraGroup" argument must be ' +
'one of type number or string. ' +

View File

@ -41,7 +41,7 @@ const assert = require('assert');
['SIGTERM', null, undefined, NaN, Infinity, -Infinity].forEach((val) => {
assert.throws(() => process.kill(val), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "pid" argument must be of type number. ' +
`Received type ${typeof val}`
});

View File

@ -16,7 +16,7 @@ assert.throws(
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "groups" argument must be of type Array. ' +
'Received type undefined'
}
@ -28,7 +28,7 @@ assert.throws(
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
name: 'RangeError',
message: 'The value of "groups[1]" is out of range. ' +
'It must be >= 0 && < 4294967296. Received -1'
}
@ -41,7 +41,7 @@ assert.throws(
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "groups[0]" argument must be ' +
'one of type number or string. ' +
`Received type ${typeof val}`

View File

@ -129,21 +129,21 @@ const { promisify } = require('util');
assert.throws(
() => finished(rs, 'foo'),
{
name: /ERR_INVALID_ARG_TYPE/,
code: 'ERR_INVALID_ARG_TYPE',
message: /callback/
}
);
assert.throws(
() => finished(rs, 'foo', () => {}),
{
name: /ERR_INVALID_ARG_TYPE/,
code: 'ERR_INVALID_ARG_TYPE',
message: /opts/
}
);
assert.throws(
() => finished(rs, {}, 'foo'),
{
name: /ERR_INVALID_ARG_TYPE/,
code: 'ERR_INVALID_ARG_TYPE',
message: /callback/
}
);

View File

@ -14,7 +14,7 @@ assert.throws(
() => new tty.WriteStream(-1),
{
code: 'ERR_INVALID_FD',
name: 'RangeError [ERR_INVALID_FD]',
name: 'RangeError',
message: '"fd" must be a positive integer: -1'
}
);
@ -38,7 +38,7 @@ assert.throws(
});
}, {
code: 'ERR_TTY_INIT_FAILED',
name: 'SystemError [ERR_TTY_INIT_FAILED]',
name: 'SystemError',
message,
info
}
@ -51,7 +51,7 @@ assert.throws(
});
}, {
code: 'ERR_TTY_INIT_FAILED',
name: 'SystemError [ERR_TTY_INIT_FAILED]',
name: 'SystemError',
message,
info
});
@ -61,7 +61,7 @@ assert.throws(
() => new tty.ReadStream(-1),
{
code: 'ERR_INVALID_FD',
name: 'RangeError [ERR_INVALID_FD]',
name: 'RangeError',
message: '"fd" must be a positive integer: -1'
}
);

View File

@ -26,7 +26,7 @@ assert.strictEqual(
() => url.format(myURL, value),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
name: 'TypeError',
message: 'The "options" argument must be of type Object. ' +
`Received type ${typeof value}`
}

View File

@ -56,15 +56,13 @@ for (const test of failureTests) {
assert.throws(
() => new URL(test.input, test.base),
(error) => {
if (!expectedError(error))
return false;
expectedError(error);
// The input could be processed, so we don't do strict matching here
const match = (`${error}`).match(/Invalid URL: (.*)$/);
if (!match) {
return false;
}
return error.input === match[1];
let match;
assert(match = (`${error}`).match(/Invalid URL: (.*)$/));
assert.strictEqual(error.input, match[1]);
return true;
});
}