mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
errors: minor (SystemError) refactoring
This removes the former default values and the spread arguments usage. That was unnecessary and now it does only what is necessary. The `message` function got renamed to `getMessage` to outline that it is actually a function and a helper function was inlined into the SystemError constructor as it was only used there. PR-URL: https://github.com/nodejs/node/pull/20337 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
4 files changed
+45
-56
No files matched your search
@@ -93,20 +93,22 @@ common.expectsError(() => {
|
||||
});
|
||||
|
||||
// Test ERR_INVALID_FD_TYPE
|
||||
assert.strictEqual(errors.message('ERR_INVALID_FD_TYPE', ['a']),
|
||||
assert.strictEqual(errors.getMessage('ERR_INVALID_FD_TYPE', ['a']),
|
||||
'Unsupported fd type: a');
|
||||
|
||||
// Test ERR_INVALID_URL_SCHEME
|
||||
assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', ['file']),
|
||||
assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', ['file']),
|
||||
'The URL must be of scheme file');
|
||||
assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['file']]),
|
||||
assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', [['file']]),
|
||||
'The URL must be of scheme file');
|
||||
assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['http', 'ftp']]),
|
||||
assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME',
|
||||
[['http', 'ftp']]),
|
||||
'The URL must be one of scheme http or ftp');
|
||||
assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['a', 'b', 'c']]),
|
||||
assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME',
|
||||
[['a', 'b', 'c']]),
|
||||
'The URL must be one of scheme a, b, or c');
|
||||
common.expectsError(
|
||||
() => errors.message('ERR_INVALID_URL_SCHEME', [[]]),
|
||||
() => errors.getMessage('ERR_INVALID_URL_SCHEME', [[]]),
|
||||
{
|
||||
code: 'ERR_ASSERTION',
|
||||
type: assert.AssertionError,
|
||||
@@ -114,74 +116,67 @@ common.expectsError(
|
||||
});
|
||||
|
||||
// Test ERR_MISSING_ARGS
|
||||
assert.strictEqual(errors.message('ERR_MISSING_ARGS', ['name']),
|
||||
assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['name']),
|
||||
'The "name" argument must be specified');
|
||||
assert.strictEqual(errors.message('ERR_MISSING_ARGS', ['name', 'value']),
|
||||
assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['name', 'value']),
|
||||
'The "name" and "value" arguments must be specified');
|
||||
assert.strictEqual(errors.message('ERR_MISSING_ARGS', ['a', 'b', 'c']),
|
||||
assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['a', 'b', 'c']),
|
||||
'The "a", "b", and "c" arguments must be specified');
|
||||
common.expectsError(
|
||||
() => errors.message('ERR_MISSING_ARGS'),
|
||||
{
|
||||
code: 'ERR_ASSERTION',
|
||||
type: assert.AssertionError,
|
||||
message: /^At least one arg needs to be specified$/
|
||||
});
|
||||
|
||||
// Test ERR_SOCKET_BAD_PORT
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_SOCKET_BAD_PORT', [0]),
|
||||
errors.getMessage('ERR_SOCKET_BAD_PORT', [0]),
|
||||
'Port should be > 0 and < 65536. Received 0.');
|
||||
|
||||
// Test ERR_TLS_CERT_ALTNAME_INVALID
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_TLS_CERT_ALTNAME_INVALID', ['altname']),
|
||||
errors.getMessage('ERR_TLS_CERT_ALTNAME_INVALID', ['altname']),
|
||||
'Hostname/IP does not match certificate\'s altnames: altname');
|
||||
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_INVALID_PROTOCOL', ['bad protocol', 'http']),
|
||||
errors.getMessage('ERR_INVALID_PROTOCOL', ['bad protocol', 'http']),
|
||||
'Protocol "bad protocol" not supported. Expected "http"'
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_HTTP_HEADERS_SENT', ['render']),
|
||||
errors.getMessage('ERR_HTTP_HEADERS_SENT', ['render']),
|
||||
'Cannot render headers after they are sent to the client'
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_INVALID_HTTP_TOKEN', ['Method', 'foo']),
|
||||
errors.getMessage('ERR_INVALID_HTTP_TOKEN', ['Method', 'foo']),
|
||||
'Method must be a valid HTTP token ["foo"]'
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_OUT_OF_RANGE', ['A', 'some values', 'B']),
|
||||
errors.getMessage('ERR_OUT_OF_RANGE', ['A', 'some values', 'B']),
|
||||
'The value of "A" is out of range. It must be some values. Received B'
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_UNESCAPED_CHARACTERS', ['Request path']),
|
||||
errors.getMessage('ERR_UNESCAPED_CHARACTERS', ['Request path']),
|
||||
'Request path contains unescaped characters'
|
||||
);
|
||||
|
||||
// Test ERR_DNS_SET_SERVERS_FAILED
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_DNS_SET_SERVERS_FAILED', ['err', 'servers']),
|
||||
errors.getMessage('ERR_DNS_SET_SERVERS_FAILED', ['err', 'servers']),
|
||||
'c-ares failed to set servers: "err" [servers]');
|
||||
|
||||
// Test ERR_ENCODING_NOT_SUPPORTED
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_ENCODING_NOT_SUPPORTED', ['enc']),
|
||||
errors.getMessage('ERR_ENCODING_NOT_SUPPORTED', ['enc']),
|
||||
'The "enc" encoding is not supported');
|
||||
|
||||
// Test error messages for async_hooks
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_ASYNC_CALLBACK', ['init']),
|
||||
errors.getMessage('ERR_ASYNC_CALLBACK', ['init']),
|
||||
'init must be a function');
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_ASYNC_TYPE', [{}]),
|
||||
errors.getMessage('ERR_ASYNC_TYPE', [{}]),
|
||||
'Invalid name for async "type": [object Object]');
|
||||
assert.strictEqual(
|
||||
errors.message('ERR_INVALID_ASYNC_ID', ['asyncId', undefined]),
|
||||
errors.getMessage('ERR_INVALID_ASYNC_ID', ['asyncId', undefined]),
|
||||
'Invalid asyncId value: undefined');
|
||||
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user