From b40efa43bd04931baf95eef0923630b8c9531c75 Mon Sep 17 00:00:00 2001 From: davidmarkclements Date: Thu, 12 Apr 2018 18:48:03 +0200 Subject: [PATCH] errors: alter ERR_INVALID_IP_ADDRESS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit changes the base instance for ERR_INVALID_IP_ADDRESS from Error to TypeError as a more accurate representation of the error. PR-URL: https://github.com/nodejs/node/pull/19979 Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat --- lib/dns.js | 2 +- lib/internal/errors.js | 3 +-- test/parallel/test-dns.js | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index fdfcec2e7ee67a..62faf32b690735 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -316,7 +316,7 @@ function setServers(servers) { return newSet.push([ipVersion, s, parseInt(p)]); } - throw new ERR_INVALID_IP_ADDRESS.Error(serv); + throw new ERR_INVALID_IP_ADDRESS(serv); }); const errorNumber = this._handle.setServers(newSet); diff --git a/lib/internal/errors.js b/lib/internal/errors.js index eff720f0905874..401051bab1ed5c 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -891,8 +891,7 @@ E('ERR_INVALID_FILE_URL_HOST', E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError); E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent', TypeError); E('ERR_INVALID_HTTP_TOKEN', '%s must be a valid HTTP token ["%s"]', TypeError); -// The `Error` should probably be a `TypeError`. -E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s', TypeError, Error); +E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s', TypeError); E('ERR_INVALID_OPT_VALUE', (name, value) => `The value "${String(value)}" is invalid for option "${name}"`, TypeError, diff --git a/test/parallel/test-dns.js b/test/parallel/test-dns.js index 839d434f9e1d65..fb648544b95469 100644 --- a/test/parallel/test-dns.js +++ b/test/parallel/test-dns.js @@ -70,12 +70,12 @@ dns.setServers(goog); assert.deepStrictEqual(dns.getServers(), goog); common.expectsError(() => dns.setServers(['foobar']), { code: 'ERR_INVALID_IP_ADDRESS', - type: Error, + type: TypeError, message: 'Invalid IP address: foobar' }); common.expectsError(() => dns.setServers(['127.0.0.1:va']), { code: 'ERR_INVALID_IP_ADDRESS', - type: Error, + type: TypeError, message: 'Invalid IP address: 127.0.0.1:va' }); assert.deepStrictEqual(dns.getServers(), goog);