2016-10-24 13:09:34 -07:00
|
|
|
// Flags: --expose-internals
|
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
2018-08-22 09:17:19 -07:00
|
|
|
const {
|
|
|
|
hijackStdout,
|
|
|
|
restoreStdout,
|
|
|
|
} = require('../common/hijackstdio');
|
2018-08-17 16:33:45 +08:00
|
|
|
|
|
|
|
const { internalBinding } = require('internal/test/binding');
|
2016-10-24 13:09:34 -07:00
|
|
|
const assert = require('assert');
|
2017-09-29 17:06:28 -07:00
|
|
|
const errors = require('internal/errors');
|
2016-10-24 13:09:34 -07:00
|
|
|
|
2018-03-06 14:17:37 +01:00
|
|
|
errors.E('TEST_ERROR_1', 'Error for testing purposes: %s',
|
|
|
|
Error, TypeError, RangeError);
|
|
|
|
errors.E('TEST_ERROR_2', (a, b) => `${a} ${b}`, Error);
|
2016-10-24 13:09:34 -07:00
|
|
|
|
2017-10-01 19:54:37 -07:00
|
|
|
{
|
2018-03-06 14:17:37 +01:00
|
|
|
const err = new errors.codes.TEST_ERROR_1('test');
|
2017-10-01 19:54:37 -07:00
|
|
|
assert(err instanceof Error);
|
|
|
|
assert.strictEqual(err.name, 'Error [TEST_ERROR_1]');
|
|
|
|
assert.strictEqual(err.message, 'Error for testing purposes: test');
|
|
|
|
assert.strictEqual(err.code, 'TEST_ERROR_1');
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-03-06 14:17:37 +01:00
|
|
|
const err = new errors.codes.TEST_ERROR_1.TypeError('test');
|
2017-10-01 19:54:37 -07:00
|
|
|
assert(err instanceof TypeError);
|
|
|
|
assert.strictEqual(err.name, 'TypeError [TEST_ERROR_1]');
|
|
|
|
assert.strictEqual(err.message, 'Error for testing purposes: test');
|
|
|
|
assert.strictEqual(err.code, 'TEST_ERROR_1');
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-03-06 14:17:37 +01:00
|
|
|
const err = new errors.codes.TEST_ERROR_1.RangeError('test');
|
2017-10-01 19:54:37 -07:00
|
|
|
assert(err instanceof RangeError);
|
|
|
|
assert.strictEqual(err.name, 'RangeError [TEST_ERROR_1]');
|
|
|
|
assert.strictEqual(err.message, 'Error for testing purposes: test');
|
|
|
|
assert.strictEqual(err.code, 'TEST_ERROR_1');
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-03-06 14:17:37 +01:00
|
|
|
const err = new errors.codes.TEST_ERROR_2('abc', 'xyz');
|
2017-10-01 19:54:37 -07:00
|
|
|
assert(err instanceof Error);
|
|
|
|
assert.strictEqual(err.name, 'Error [TEST_ERROR_2]');
|
|
|
|
assert.strictEqual(err.message, 'abc xyz');
|
|
|
|
assert.strictEqual(err.code, 'TEST_ERROR_2');
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-04-11 03:10:22 +02:00
|
|
|
assert.throws(
|
|
|
|
() => new errors.codes.TEST_ERROR_1(),
|
|
|
|
{
|
|
|
|
message: 'Code: TEST_ERROR_1; The provided arguments ' +
|
|
|
|
'length (0) does not match the required ones (1).'
|
|
|
|
}
|
|
|
|
);
|
2017-10-01 19:54:37 -07:00
|
|
|
}
|
2017-03-14 00:11:35 +08:00
|
|
|
|
2016-10-24 13:09:34 -07:00
|
|
|
// Tests for common.expectsError
|
2018-02-09 02:32:04 +01:00
|
|
|
common.expectsError(() => {
|
2018-03-06 14:17:37 +01:00
|
|
|
throw new errors.codes.TEST_ERROR_1.TypeError('a');
|
2018-02-09 02:32:04 +01:00
|
|
|
}, { code: 'TEST_ERROR_1' });
|
|
|
|
common.expectsError(() => {
|
2018-03-06 14:17:37 +01:00
|
|
|
throw new errors.codes.TEST_ERROR_1.TypeError('a');
|
2018-02-09 02:32:04 +01:00
|
|
|
}, { code: 'TEST_ERROR_1',
|
|
|
|
type: TypeError,
|
|
|
|
message: /^Error for testing/ });
|
|
|
|
common.expectsError(() => {
|
2018-03-06 14:17:37 +01:00
|
|
|
throw new errors.codes.TEST_ERROR_1.TypeError('a');
|
2018-02-09 02:32:04 +01:00
|
|
|
}, { code: 'TEST_ERROR_1', type: TypeError });
|
|
|
|
common.expectsError(() => {
|
2018-03-06 14:17:37 +01:00
|
|
|
throw new errors.codes.TEST_ERROR_1.TypeError('a');
|
2018-02-09 02:32:04 +01:00
|
|
|
}, {
|
|
|
|
code: 'TEST_ERROR_1',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'Error for testing purposes: a'
|
2016-10-24 13:09:34 -07:00
|
|
|
});
|
|
|
|
|
2017-12-06 22:16:44 +05:30
|
|
|
common.expectsError(() => {
|
|
|
|
common.expectsError(() => {
|
2018-03-06 14:17:37 +01:00
|
|
|
throw new errors.codes.TEST_ERROR_1.TypeError('a');
|
2017-12-06 22:16:44 +05:30
|
|
|
}, { code: 'TEST_ERROR_1', type: RangeError });
|
|
|
|
}, {
|
2017-04-25 13:18:25 -07:00
|
|
|
code: 'ERR_ASSERTION',
|
2018-07-03 02:06:57 +02:00
|
|
|
message: /\+ type: \[Function: TypeError]\n- type: \[Function: RangeError]/
|
2017-12-06 22:16:44 +05:30
|
|
|
});
|
2016-10-24 13:09:34 -07:00
|
|
|
|
2017-12-06 22:16:44 +05:30
|
|
|
common.expectsError(() => {
|
|
|
|
common.expectsError(() => {
|
2018-03-06 14:17:37 +01:00
|
|
|
throw new errors.codes.TEST_ERROR_1.TypeError('a');
|
2017-12-06 22:16:44 +05:30
|
|
|
}, { code: 'TEST_ERROR_1',
|
|
|
|
type: TypeError,
|
|
|
|
message: /^Error for testing 2/ });
|
|
|
|
}, {
|
2017-04-25 13:18:25 -07:00
|
|
|
code: 'ERR_ASSERTION',
|
2017-06-19 15:24:04 -04:00
|
|
|
type: assert.AssertionError,
|
2018-09-10 08:58:46 +02:00
|
|
|
message: /\+ message: 'Error for testing purposes: a',\n- message: \/\^Error/
|
2017-12-06 22:16:44 +05:30
|
|
|
});
|
2017-03-14 00:11:35 +08:00
|
|
|
|
2017-08-12 00:02:15 +03:00
|
|
|
// Test ERR_INVALID_FD_TYPE
|
2018-04-26 19:12:47 +02:00
|
|
|
assert.strictEqual(errors.getMessage('ERR_INVALID_FD_TYPE', ['a']),
|
2017-08-12 00:02:15 +03:00
|
|
|
'Unsupported fd type: a');
|
|
|
|
|
2017-04-21 11:54:58 -07:00
|
|
|
// Test ERR_INVALID_URL_SCHEME
|
2018-04-26 19:12:47 +02:00
|
|
|
assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', ['file']),
|
2017-04-21 11:54:58 -07:00
|
|
|
'The URL must be of scheme file');
|
2018-04-26 19:12:47 +02:00
|
|
|
assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', [['file']]),
|
2017-04-21 11:54:58 -07:00
|
|
|
'The URL must be of scheme file');
|
2018-04-26 19:12:47 +02:00
|
|
|
assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME',
|
|
|
|
[['http', 'ftp']]),
|
2017-04-21 11:54:58 -07:00
|
|
|
'The URL must be one of scheme http or ftp');
|
2018-04-26 19:12:47 +02:00
|
|
|
assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME',
|
|
|
|
[['a', 'b', 'c']]),
|
2017-04-21 11:54:58 -07:00
|
|
|
'The URL must be one of scheme a, b, or c');
|
2017-12-06 22:16:44 +05:30
|
|
|
common.expectsError(
|
2018-04-26 19:12:47 +02:00
|
|
|
() => errors.getMessage('ERR_INVALID_URL_SCHEME', [[]]),
|
2017-12-06 22:16:44 +05:30
|
|
|
{
|
2017-04-25 13:18:25 -07:00
|
|
|
code: 'ERR_ASSERTION',
|
2017-06-19 15:24:04 -04:00
|
|
|
type: assert.AssertionError,
|
2017-04-25 13:18:25 -07:00
|
|
|
message: /^At least one expected value needs to be specified$/
|
2017-12-06 22:16:44 +05:30
|
|
|
});
|
2017-04-21 11:54:58 -07:00
|
|
|
|
|
|
|
// Test ERR_MISSING_ARGS
|
2018-04-26 19:12:47 +02:00
|
|
|
assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['name']),
|
2017-04-21 11:54:58 -07:00
|
|
|
'The "name" argument must be specified');
|
2018-04-26 19:12:47 +02:00
|
|
|
assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['name', 'value']),
|
2017-04-21 11:54:58 -07:00
|
|
|
'The "name" and "value" arguments must be specified');
|
2018-04-26 19:12:47 +02:00
|
|
|
assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['a', 'b', 'c']),
|
2017-04-21 11:54:58 -07:00
|
|
|
'The "a", "b", and "c" arguments must be specified');
|
2017-06-29 19:20:11 -04:00
|
|
|
|
2017-08-12 00:02:15 +03:00
|
|
|
// Test ERR_SOCKET_BAD_PORT
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_SOCKET_BAD_PORT', [0]),
|
2018-09-22 02:28:03 -05:00
|
|
|
'Port should be >= 0 and < 65536. Received 0.');
|
2017-06-29 19:20:11 -04:00
|
|
|
|
|
|
|
// Test ERR_TLS_CERT_ALTNAME_INVALID
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_TLS_CERT_ALTNAME_INVALID', ['altname']),
|
2017-07-25 10:37:08 -07:00
|
|
|
'Hostname/IP does not match certificate\'s altnames: altname');
|
2017-07-22 19:23:04 +08:00
|
|
|
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_INVALID_PROTOCOL', ['bad protocol', 'http']),
|
2017-07-22 19:23:04 +08:00
|
|
|
'Protocol "bad protocol" not supported. Expected "http"'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_HTTP_HEADERS_SENT', ['render']),
|
2017-07-22 19:23:04 +08:00
|
|
|
'Cannot render headers after they are sent to the client'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_INVALID_HTTP_TOKEN', ['Method', 'foo']),
|
2017-08-10 18:58:22 +08:00
|
|
|
'Method must be a valid HTTP token ["foo"]'
|
2017-07-22 19:23:04 +08:00
|
|
|
);
|
|
|
|
|
2017-12-13 20:48:43 +08:00
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_OUT_OF_RANGE', ['A', 'some values', 'B']),
|
2017-12-13 20:48:43 +08:00
|
|
|
'The value of "A" is out of range. It must be some values. Received B'
|
2017-08-07 14:42:55 +08:00
|
|
|
);
|
|
|
|
|
2017-07-22 19:23:04 +08:00
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_UNESCAPED_CHARACTERS', ['Request path']),
|
2017-07-22 19:23:04 +08:00
|
|
|
'Request path contains unescaped characters'
|
|
|
|
);
|
async_hooks: don't abort unnecessarily
* id values of -1 are allowed. They indicate that the id was never
correctly assigned to the async resource. These will appear in any
call graph, and will only be apparent to those using the async_hooks
module, then reported in an issue.
* ids < -1 are still not allowed and will cause the application to
exit the process; because there is no scenario where this should ever
happen.
* Add asyncId range checks to emitAfterScript().
* Fix emitBeforeScript() range checks which should have been || not &&.
* Replace errors with entries in internal/errors.
* Fix async_hooks tests that check for exceptions to match new
internal/errors entries.
NOTE: emit{Before,After,Destroy}() must continue to exit the process
because in the case of an exception during hook execution the state of
the application is unknowable. For example, an exception could cause a
memory leak:
const id_map = new Map();
before(id) {
id_map.set(id, /* data object or similar */);
},
after(id) {
throw new Error('id never dies!');
id_map.delete(id);
}
Allowing a recoverable exception may also cause an abort because of a
stack check in Environment::AsyncHooks::pop_ids() that verifies the
async id and pop'd ids match. This case would be more difficult to debug
than if fatalError() (lib/async_hooks.js) was called immediately.
try {
async_hooks.emitBefore(null, NaN);
} catch (e) { }
// do something
async_hooks.emitAfter(5);
It also allows an edge case where emitBefore() could be called twice and
not have the pop_ids() CHECK fail:
try {
async_hooks.emitBefore(5, NaN);
} catch (e) { }
async_hooks.emitBefore(5);
// do something
async_hooks.emitAfter(5);
There is the option of allowing mismatches in the stack and ignoring the
check if no async hooks are enabled, but I don't believe going this far
is necessary.
PR-URL: https://github.com/nodejs/node/pull/14722
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-08-03 14:43:41 -06:00
|
|
|
|
2017-10-06 13:36:22 -07:00
|
|
|
// Test ERR_DNS_SET_SERVERS_FAILED
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_DNS_SET_SERVERS_FAILED', ['err', 'servers']),
|
2017-10-06 13:36:22 -07:00
|
|
|
'c-ares failed to set servers: "err" [servers]');
|
|
|
|
|
|
|
|
// Test ERR_ENCODING_NOT_SUPPORTED
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_ENCODING_NOT_SUPPORTED', ['enc']),
|
2017-10-06 13:36:22 -07:00
|
|
|
'The "enc" encoding is not supported');
|
|
|
|
|
async_hooks: don't abort unnecessarily
* id values of -1 are allowed. They indicate that the id was never
correctly assigned to the async resource. These will appear in any
call graph, and will only be apparent to those using the async_hooks
module, then reported in an issue.
* ids < -1 are still not allowed and will cause the application to
exit the process; because there is no scenario where this should ever
happen.
* Add asyncId range checks to emitAfterScript().
* Fix emitBeforeScript() range checks which should have been || not &&.
* Replace errors with entries in internal/errors.
* Fix async_hooks tests that check for exceptions to match new
internal/errors entries.
NOTE: emit{Before,After,Destroy}() must continue to exit the process
because in the case of an exception during hook execution the state of
the application is unknowable. For example, an exception could cause a
memory leak:
const id_map = new Map();
before(id) {
id_map.set(id, /* data object or similar */);
},
after(id) {
throw new Error('id never dies!');
id_map.delete(id);
}
Allowing a recoverable exception may also cause an abort because of a
stack check in Environment::AsyncHooks::pop_ids() that verifies the
async id and pop'd ids match. This case would be more difficult to debug
than if fatalError() (lib/async_hooks.js) was called immediately.
try {
async_hooks.emitBefore(null, NaN);
} catch (e) { }
// do something
async_hooks.emitAfter(5);
It also allows an edge case where emitBefore() could be called twice and
not have the pop_ids() CHECK fail:
try {
async_hooks.emitBefore(5, NaN);
} catch (e) { }
async_hooks.emitBefore(5);
// do something
async_hooks.emitAfter(5);
There is the option of allowing mismatches in the stack and ignoring the
check if no async hooks are enabled, but I don't believe going this far
is necessary.
PR-URL: https://github.com/nodejs/node/pull/14722
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-08-03 14:43:41 -06:00
|
|
|
// Test error messages for async_hooks
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_ASYNC_CALLBACK', ['init']),
|
async_hooks: don't abort unnecessarily
* id values of -1 are allowed. They indicate that the id was never
correctly assigned to the async resource. These will appear in any
call graph, and will only be apparent to those using the async_hooks
module, then reported in an issue.
* ids < -1 are still not allowed and will cause the application to
exit the process; because there is no scenario where this should ever
happen.
* Add asyncId range checks to emitAfterScript().
* Fix emitBeforeScript() range checks which should have been || not &&.
* Replace errors with entries in internal/errors.
* Fix async_hooks tests that check for exceptions to match new
internal/errors entries.
NOTE: emit{Before,After,Destroy}() must continue to exit the process
because in the case of an exception during hook execution the state of
the application is unknowable. For example, an exception could cause a
memory leak:
const id_map = new Map();
before(id) {
id_map.set(id, /* data object or similar */);
},
after(id) {
throw new Error('id never dies!');
id_map.delete(id);
}
Allowing a recoverable exception may also cause an abort because of a
stack check in Environment::AsyncHooks::pop_ids() that verifies the
async id and pop'd ids match. This case would be more difficult to debug
than if fatalError() (lib/async_hooks.js) was called immediately.
try {
async_hooks.emitBefore(null, NaN);
} catch (e) { }
// do something
async_hooks.emitAfter(5);
It also allows an edge case where emitBefore() could be called twice and
not have the pop_ids() CHECK fail:
try {
async_hooks.emitBefore(5, NaN);
} catch (e) { }
async_hooks.emitBefore(5);
// do something
async_hooks.emitAfter(5);
There is the option of allowing mismatches in the stack and ignoring the
check if no async hooks are enabled, but I don't believe going this far
is necessary.
PR-URL: https://github.com/nodejs/node/pull/14722
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-08-03 14:43:41 -06:00
|
|
|
'init must be a function');
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_ASYNC_TYPE', [{}]),
|
async_hooks: don't abort unnecessarily
* id values of -1 are allowed. They indicate that the id was never
correctly assigned to the async resource. These will appear in any
call graph, and will only be apparent to those using the async_hooks
module, then reported in an issue.
* ids < -1 are still not allowed and will cause the application to
exit the process; because there is no scenario where this should ever
happen.
* Add asyncId range checks to emitAfterScript().
* Fix emitBeforeScript() range checks which should have been || not &&.
* Replace errors with entries in internal/errors.
* Fix async_hooks tests that check for exceptions to match new
internal/errors entries.
NOTE: emit{Before,After,Destroy}() must continue to exit the process
because in the case of an exception during hook execution the state of
the application is unknowable. For example, an exception could cause a
memory leak:
const id_map = new Map();
before(id) {
id_map.set(id, /* data object or similar */);
},
after(id) {
throw new Error('id never dies!');
id_map.delete(id);
}
Allowing a recoverable exception may also cause an abort because of a
stack check in Environment::AsyncHooks::pop_ids() that verifies the
async id and pop'd ids match. This case would be more difficult to debug
than if fatalError() (lib/async_hooks.js) was called immediately.
try {
async_hooks.emitBefore(null, NaN);
} catch (e) { }
// do something
async_hooks.emitAfter(5);
It also allows an edge case where emitBefore() could be called twice and
not have the pop_ids() CHECK fail:
try {
async_hooks.emitBefore(5, NaN);
} catch (e) { }
async_hooks.emitBefore(5);
// do something
async_hooks.emitAfter(5);
There is the option of allowing mismatches in the stack and ignoring the
check if no async hooks are enabled, but I don't believe going this far
is necessary.
PR-URL: https://github.com/nodejs/node/pull/14722
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-08-03 14:43:41 -06:00
|
|
|
'Invalid name for async "type": [object Object]');
|
|
|
|
assert.strictEqual(
|
2018-04-26 19:12:47 +02:00
|
|
|
errors.getMessage('ERR_INVALID_ASYNC_ID', ['asyncId', undefined]),
|
async_hooks: don't abort unnecessarily
* id values of -1 are allowed. They indicate that the id was never
correctly assigned to the async resource. These will appear in any
call graph, and will only be apparent to those using the async_hooks
module, then reported in an issue.
* ids < -1 are still not allowed and will cause the application to
exit the process; because there is no scenario where this should ever
happen.
* Add asyncId range checks to emitAfterScript().
* Fix emitBeforeScript() range checks which should have been || not &&.
* Replace errors with entries in internal/errors.
* Fix async_hooks tests that check for exceptions to match new
internal/errors entries.
NOTE: emit{Before,After,Destroy}() must continue to exit the process
because in the case of an exception during hook execution the state of
the application is unknowable. For example, an exception could cause a
memory leak:
const id_map = new Map();
before(id) {
id_map.set(id, /* data object or similar */);
},
after(id) {
throw new Error('id never dies!');
id_map.delete(id);
}
Allowing a recoverable exception may also cause an abort because of a
stack check in Environment::AsyncHooks::pop_ids() that verifies the
async id and pop'd ids match. This case would be more difficult to debug
than if fatalError() (lib/async_hooks.js) was called immediately.
try {
async_hooks.emitBefore(null, NaN);
} catch (e) { }
// do something
async_hooks.emitAfter(5);
It also allows an edge case where emitBefore() could be called twice and
not have the pop_ids() CHECK fail:
try {
async_hooks.emitBefore(5, NaN);
} catch (e) { }
async_hooks.emitBefore(5);
// do something
async_hooks.emitAfter(5);
There is the option of allowing mismatches in the stack and ignoring the
check if no async hooks are enabled, but I don't believe going this far
is necessary.
PR-URL: https://github.com/nodejs/node/pull/14722
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-08-03 14:43:41 -06:00
|
|
|
'Invalid asyncId value: undefined');
|
2017-09-25 16:48:57 -07:00
|
|
|
|
|
|
|
{
|
2018-08-17 16:33:45 +08:00
|
|
|
const { kMaxLength } = internalBinding('buffer');
|
2018-03-06 14:17:37 +01:00
|
|
|
const error = new errors.codes.ERR_BUFFER_TOO_LARGE();
|
2017-09-25 16:48:57 -07:00
|
|
|
assert.strictEqual(
|
|
|
|
error.message,
|
|
|
|
`Cannot create a Buffer larger than 0x${kMaxLength.toString(16)} bytes`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-03-06 14:17:37 +01:00
|
|
|
const error = new errors.codes.ERR_INVALID_ARG_VALUE('foo', '\u0000bar');
|
2017-09-25 16:48:57 -07:00
|
|
|
assert.strictEqual(
|
|
|
|
error.message,
|
2018-01-25 04:39:02 +08:00
|
|
|
'The argument \'foo\' is invalid. Received \'\\u0000bar\''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-03-06 14:17:37 +01:00
|
|
|
const error = new errors.codes.ERR_INVALID_ARG_VALUE(
|
|
|
|
'foo', { a: 1 }, 'must have property \'b\''
|
|
|
|
);
|
2018-01-25 04:39:02 +08:00
|
|
|
assert.strictEqual(
|
|
|
|
error.message,
|
|
|
|
'The argument \'foo\' must have property \'b\'. Received { a: 1 }'
|
2017-09-25 16:48:57 -07:00
|
|
|
);
|
|
|
|
}
|
2017-09-29 17:06:28 -07:00
|
|
|
|
|
|
|
// Test that `code` property is mutable and that changing it does not change the
|
|
|
|
// name.
|
|
|
|
{
|
2018-03-06 14:17:37 +01:00
|
|
|
const myError = new errors.codes.ERR_TLS_HANDSHAKE_TIMEOUT();
|
2017-09-29 17:06:28 -07:00
|
|
|
assert.strictEqual(myError.code, 'ERR_TLS_HANDSHAKE_TIMEOUT');
|
2017-10-01 16:14:45 -07:00
|
|
|
assert.strictEqual(myError.hasOwnProperty('code'), false);
|
|
|
|
assert.strictEqual(myError.hasOwnProperty('name'), false);
|
|
|
|
assert.deepStrictEqual(Object.keys(myError), []);
|
2017-09-29 17:06:28 -07:00
|
|
|
const initialName = myError.name;
|
|
|
|
myError.code = 'FHQWHGADS';
|
|
|
|
assert.strictEqual(myError.code, 'FHQWHGADS');
|
|
|
|
assert.strictEqual(myError.name, initialName);
|
2017-10-01 16:14:45 -07:00
|
|
|
assert.deepStrictEqual(Object.keys(myError), ['code']);
|
2017-09-29 17:06:28 -07:00
|
|
|
assert.ok(myError.name.includes('ERR_TLS_HANDSHAKE_TIMEOUT'));
|
|
|
|
assert.ok(!myError.name.includes('FHQWHGADS'));
|
|
|
|
}
|
|
|
|
|
2017-10-01 16:14:45 -07:00
|
|
|
// Test that `name` is mutable and that changing it alters `toString()` but not
|
|
|
|
// `console.log()` results, which is the behavior of `Error` objects in the
|
|
|
|
// browser. Note that `name` becomes enumerable after being assigned.
|
2017-09-29 17:06:28 -07:00
|
|
|
{
|
2018-03-06 14:17:37 +01:00
|
|
|
const myError = new errors.codes.ERR_TLS_HANDSHAKE_TIMEOUT();
|
2017-10-01 16:14:45 -07:00
|
|
|
assert.deepStrictEqual(Object.keys(myError), []);
|
|
|
|
const initialToString = myError.toString();
|
|
|
|
|
|
|
|
myError.name = 'Fhqwhgads';
|
|
|
|
assert.deepStrictEqual(Object.keys(myError), ['name']);
|
|
|
|
assert.notStrictEqual(myError.toString(), initialToString);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that `message` is mutable and that changing it alters `toString()` but
|
|
|
|
// not `console.log()` results, which is the behavior of `Error` objects in the
|
|
|
|
// browser. Note that `message` remains non-enumerable after being assigned.
|
|
|
|
{
|
|
|
|
let initialConsoleLog = '';
|
2018-08-22 09:17:19 -07:00
|
|
|
hijackStdout((data) => { initialConsoleLog += data; });
|
2018-03-06 14:17:37 +01:00
|
|
|
const myError = new errors.codes.ERR_TLS_HANDSHAKE_TIMEOUT();
|
2017-10-01 16:14:45 -07:00
|
|
|
assert.deepStrictEqual(Object.keys(myError), []);
|
|
|
|
const initialToString = myError.toString();
|
|
|
|
console.log(myError);
|
|
|
|
assert.notStrictEqual(initialConsoleLog, '');
|
|
|
|
|
2018-08-22 09:17:19 -07:00
|
|
|
restoreStdout();
|
2017-10-01 16:14:45 -07:00
|
|
|
|
|
|
|
let subsequentConsoleLog = '';
|
2018-08-22 09:17:19 -07:00
|
|
|
hijackStdout((data) => { subsequentConsoleLog += data; });
|
2017-10-01 16:14:45 -07:00
|
|
|
myError.message = 'Fhqwhgads';
|
|
|
|
assert.deepStrictEqual(Object.keys(myError), []);
|
|
|
|
assert.notStrictEqual(myError.toString(), initialToString);
|
|
|
|
console.log(myError);
|
|
|
|
assert.strictEqual(subsequentConsoleLog, initialConsoleLog);
|
|
|
|
|
2018-08-22 09:17:19 -07:00
|
|
|
restoreStdout();
|
2017-09-29 17:06:28 -07:00
|
|
|
}
|