diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-26 19:12:47 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-30 16:51:58 +0200 |
commit | 109cfa1511cb504866c44314d92552285a236b1c (patch) | |
tree | 2714839eac3b4ff88541719571e93069da584dd0 /test/parallel | |
parent | 0deb27bd291a907816a337b08198c1c08f5a09e1 (diff) | |
download | android-node-v8-109cfa1511cb504866c44314d92552285a236b1c.tar.gz android-node-v8-109cfa1511cb504866c44314d92552285a236b1c.tar.bz2 android-node-v8-109cfa1511cb504866c44314d92552285a236b1c.zip |
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>
Diffstat (limited to 'test/parallel')
-rw-r--r-- | test/parallel/test-buffer-fill.js | 8 | ||||
-rw-r--r-- | test/parallel/test-errors-systemerror.js | 8 | ||||
-rw-r--r-- | test/parallel/test-internal-errors.js | 51 |
3 files changed, 29 insertions, 38 deletions
diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js index b2f14c3e42..4eef0edefc 100644 --- a/test/parallel/test-buffer-fill.js +++ b/test/parallel/test-buffer-fill.js @@ -2,7 +2,7 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); -const errors = require('internal/errors'); +const { codes: { ERR_INDEX_OUT_OF_RANGE } } = require('internal/errors'); const SIZE = 28; const buf1 = Buffer.allocUnsafe(SIZE); @@ -214,13 +214,11 @@ function genBuffer(size, args) { return b.fill(0).fill.apply(b, args); } - function bufReset() { buf1.fill(0); buf2.fill(0); } - // This is mostly accurate. Except write() won't write partial bytes to the // string while fill() blindly copies bytes into memory. To account for that an // error will be thrown if not all the data can be written, and the SIZE has @@ -237,8 +235,9 @@ function writeToFill(string, offset, end, encoding) { end = buf2.length; } + // Should never be reached. if (offset < 0 || end > buf2.length) - throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); + throw new ERR_INDEX_OUT_OF_RANGE(); if (end <= offset) return buf2; @@ -266,7 +265,6 @@ function writeToFill(string, offset, end, encoding) { return buf2; } - function testBufs(string, offset, length, encoding) { bufReset(); buf1.fill.apply(buf1, arguments); diff --git a/test/parallel/test-errors-systemerror.js b/test/parallel/test-errors-systemerror.js index a74d7b3846..957a0dd7b2 100644 --- a/test/parallel/test-errors-systemerror.js +++ b/test/parallel/test-errors-systemerror.js @@ -3,12 +3,10 @@ require('../common'); const assert = require('assert'); -const errors = require('internal/errors'); - -const { E, SystemError } = errors; +const { E, SystemError, codes } = require('internal/errors'); assert.throws( - () => { throw new errors.SystemError(); }, + () => { throw new SystemError(); }, { name: 'TypeError', message: 'Cannot read property \'match\' of undefined' @@ -16,7 +14,7 @@ assert.throws( ); E('ERR_TEST', 'custom message', SystemError); -const { ERR_TEST } = errors.codes; +const { ERR_TEST } = codes; { const ctx = { diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js index f3ca3c99ac..b5e08911b8 100644 --- a/test/parallel/test-internal-errors.js +++ b/test/parallel/test-internal-errors.js @@ -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'); { |