| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3566195 commit 9cb390d
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -596,6 +596,10 @@ Used when `Console` is instantiated without `stdout` stream or when `stdout` or | |||
| 596 | 596 | ||
| 597 | 597 | Used when the native call from `process.cpuUsage` cannot be processed properly. | |
| 598 | 598 | ||
| 599 | + <a id="ERR_DNS_SET_SERVERS_FAILED"></a> | ||
| 600 | + | ||
| 601 | + Used when `c-ares` failed to set the DNS server. | ||
| 602 | + | ||
| 599 | 603 | <a id="ERR_FALSY_VALUE_REJECTION"></a> | |
| 600 | 604 | ### ERR_FALSY_VALUE_REJECTION | |
| 601 | 605 | ||
@@ -685,6 +689,10 @@ Used when an attempt is made to send an unsupported "handle" over an IPC | |||
| 685 | 689 | communication channel to a child process. See [`child.send()`] and | |
| 686 | 690 | [`process.send()`] for more information. | |
| 687 | 691 | ||
| 692 | + <a id="ERR_INVALID_IP_ADDRESS"></a> | ||
| 693 | + | ||
| 694 | + Used when an IP address is not valid. | ||
| 695 | + | ||
| 688 | 696 | <a id="ERR_INVALID_OPT_VALUE"></a> | |
| 689 | 697 | ### ERR_INVALID_OPT_VALUE | |
| 690 | 698 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,7 @@ const cares = process.binding('cares_wrap'); | |||
| 27 | 27 | const uv = process.binding('uv'); | |
| 28 | 28 | const internalNet = require('internal/net'); | |
| 29 | 29 | const { customPromisifyArgs } = require('internal/util'); | |
| 30 | + const errors = require('internal/errors'); | ||
| 30 | 31 | ||
| 31 | 32 | const GetAddrInfoReqWrap = cares.GetAddrInfoReqWrap; | |
| 32 | 33 | const GetNameInfoReqWrap = cares.GetNameInfoReqWrap; | |
@@ -126,13 +127,13 @@ function lookup(hostname, options, callback) { | |||
| 126 | 127 | ||
| 127 | 128 | // Parse arguments | |
| 128 | 129 | if (hostname && typeof hostname !== 'string') { | |
| 129 | - throw new TypeError('Invalid arguments: ' + | ||
| 130 | - 'hostname must be a string or falsey'); | ||
| 130 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'hostname', | ||
| 131 | + ['string', 'falsey'], hostname); | ||
| 131 | 132 | } else if (typeof options === 'function') { | |
| 132 | 133 | callback = options; | |
| 133 | 134 | family = 0; | |
| 134 | 135 | } else if (typeof callback !== 'function') { | |
| 135 | - throw new TypeError('Invalid arguments: callback must be passed'); | ||
| 136 | + throw new errors.TypeError('ERR_INVALID_CALLBACK'); | ||
| 136 | 137 | } else if (options !== null && typeof options === 'object') { | |
| 137 | 138 | hints = options.hints >>> 0; | |
| 138 | 139 | family = options.family >>> 0; | |
@@ -142,14 +143,14 @@ function lookup(hostname, options, callback) { | |||
| 142 | 143 | hints !== cares.AI_ADDRCONFIG && | |
| 143 | 144 | hints !== cares.AI_V4MAPPED && | |
| 144 | 145 | hints !== (cares.AI_ADDRCONFIG | cares.AI_V4MAPPED)) { | |
| 145 | - throw new TypeError('Invalid argument: hints must use valid flags'); | ||
| 146 | + throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'hints', hints); | ||
| 146 | 147 | } | |
| 147 | 148 | } else { | |
| 148 | 149 | family = options >>> 0; | |
| 149 | 150 | } | |
| 150 | 151 | ||
| 151 | 152 | if (family !== 0 && family !== 4 && family !== 6) | |
| 152 | - throw new TypeError('Invalid argument: family must be 4 or 6'); | ||
| 153 | + throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'family', family); | ||
| 153 | 154 | ||
| 154 | 155 | if (!hostname) { | |
| 155 | 156 | if (all) { | |
@@ -200,16 +201,16 @@ function onlookupservice(err, host, service) { | |||
| 200 | 201 | // lookupService(address, port, callback) | |
| 201 | 202 | function lookupService(host, port, callback) { | |
| 202 | 203 | if (arguments.length !== 3) | |
| 203 | - throw new Error('Invalid arguments'); | ||
| 204 | + throw new errors.TypeError('ERR_MISSING_ARGS', 'host', 'port', 'callback'); | ||
| 204 | 205 | ||
| 205 | 206 | if (isIP(host) === 0) | |
| 206 | - throw new TypeError('"host" argument needs to be a valid IP address'); | ||
| 207 | + throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'host', host); | ||
| 207 | 208 | ||
| 208 | 209 | if (!isLegalPort(port)) | |
| 209 | - throw new TypeError(`"port" should be >= 0 and < 65536, got "${port}"`); | ||
| 210 | + throw new errors.RangeError('ERR_SOCKET_BAD_PORT'); | ||
| 210 | 211 | ||
| 211 | 212 | if (typeof callback !== 'function') | |
| 212 | - throw new TypeError('"callback" argument must be a function'); | ||
| 213 | + throw new errors.TypeError('ERR_INVALID_CALLBACK'); | ||
| 213 | 214 | ||
| 214 | 215 | port = +port; | |
| 215 | 216 | ||
@@ -250,9 +251,10 @@ function resolver(bindingName) { | |||
| 250 | 251 | } | |
| 251 | 252 | ||
| 252 | 253 | if (typeof name !== 'string') { | |
| 253 | - throw new Error('"name" argument must be a string'); | ||
| 254 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'name', | ||
| 255 | + 'string', name); | ||
| 254 | 256 | } else if (typeof callback !== 'function') { | |
| 255 | - throw new Error('"callback" argument must be a function'); | ||
| 257 | + throw new errors.TypeError('ERR_INVALID_CALLBACK'); | ||
| 256 | 258 | } | |
| 257 | 259 | ||
| 258 | 260 | var req = new QueryReqWrap(); | |
@@ -290,13 +292,14 @@ function resolve(hostname, rrtype, callback) { | |||
| 290 | 292 | resolver = resolveMap.A; | |
| 291 | 293 | callback = rrtype; | |
| 292 | 294 | } else { | |
| 293 | - throw new TypeError('"rrtype" argument must be a string'); | ||
| 295 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'rrtype', | ||
| 296 | + 'string', rrtype); | ||
| 294 | 297 | } | |
| 295 | 298 | ||
| 296 | 299 | if (typeof resolver === 'function') { | |
| 297 | 300 | return resolver(hostname, callback); | |
| 298 | 301 | } else { | |
| 299 | - throw new Error(`Unknown type "${rrtype}"`); | ||
| 302 | + throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'rrtype', rrtype); | ||
| 300 | 303 | } | |
| 301 | 304 | } | |
| 302 | 305 | ||
@@ -344,7 +347,7 @@ function setServers(servers) { | |||
| 344 | 347 | return newSet.push([ipVersion, s, parseInt(p)]); | |
| 345 | 348 | } | |
| 346 | 349 | ||
| 347 | - throw new Error(`IP address is not properly formatted: ${serv}`); | ||
| 350 | + throw new errors.Error('ERR_INVALID_IP_ADDRESS', serv); | ||
| 348 | 351 | }); | |
| 349 | 352 | ||
| 350 | 353 | const errorNumber = cares.setServers(newSet); | |
@@ -354,7 +357,7 @@ function setServers(servers) { | |||
| 354 | 357 | cares.setServers(orig.join(',')); | |
| 355 | 358 | ||
| 356 | 359 | var err = cares.strerror(errorNumber); | |
| 357 | - throw new Error(`c-ares failed to set servers: "${err}" [${servers}]`); | ||
| 360 | + throw new errors.Error('ERR_DNS_SET_SERVERS_FAILED', err, servers); | ||
| 358 | 361 | } | |
| 359 | 362 | } | |
| 360 | 363 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,6 +106,8 @@ E('ERR_CHILD_CLOSED_BEFORE_REPLY', 'Child closed before reply received'); | |||
| 106 | 106 | E('ERR_CONSOLE_WRITABLE_STREAM', | |
| 107 | 107 | 'Console expects a writable stream instance for %s'); | |
| 108 | 108 | E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s'); | |
| 109 | + E('ERR_DNS_SET_SERVERS_FAILED', (err, servers) => | ||
| 110 | + `c-ares failed to set servers: "${err}" [${servers}]`); | ||
| 109 | 111 | E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value'); | |
| 110 | 112 | E('ERR_HTTP_HEADERS_SENT', | |
| 111 | 113 | 'Cannot render headers after they are sent to the client'); | |
@@ -129,6 +131,7 @@ E('ERR_INVALID_FILE_URL_HOST', | |||
| 129 | 131 | 'File URL host must be "localhost" or empty on %s'); | |
| 130 | 132 | E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s'); | |
| 131 | 133 | E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent'); | |
| 134 | + E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s'); | ||
| 132 | 135 | E('ERR_INVALID_OPT_VALUE', | |
| 133 | 136 | (name, value) => { | |
| 134 | 137 | return `The value "${String(value)}" is invalid for option "${name}"`; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,11 +46,21 @@ dns.lookup('::1', common.mustCall((error, result, addressType) => { | |||
| 46 | 46 | assert.strictEqual(6, addressType); | |
| 47 | 47 | })); | |
| 48 | 48 | ||
| 49 | - // Try calling resolve with an unsupported type. | ||
| 50 | - assert.throws(() => dns.resolve('www.google.com', 'HI'), /Unknown type/); | ||
| 51 | - | ||
| 52 | - // Try calling resolve with an unsupported type that's an object key | ||
| 53 | - assert.throws(() => dns.resolve('www.google.com', 'toString'), /Unknown type/); | ||
| 49 | + [ | ||
| 50 | + // Try calling resolve with an unsupported type. | ||
| 51 | + 'HI', | ||
| 52 | + // Try calling resolve with an unsupported type that's an object key | ||
| 53 | + 'toString' | ||
| 54 | + ].forEach((val) => { | ||
| 55 | + common.expectsError( | ||
| 56 | + () => dns.resolve('www.google.com', val), | ||
| 57 | + { | ||
| 58 | + code: 'ERR_INVALID_OPT_VALUE', | ||
| 59 | + type: TypeError, | ||
| 60 | + message: `The value "${val}" is invalid for option "rrtype"` | ||
| 61 | + } | ||
| 62 | + ); | ||
| 63 | + }); | ||
| 54 | 64 | ||
| 55 | 65 | // Windows doesn't usually have an entry for localhost 127.0.0.1 in | |
| 56 | 66 | // C:\Windows\System32\drivers\etc\hosts | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,31 +9,49 @@ cares.getaddrinfo = () => process.binding('uv').UV_ENOENT; | |||
| 9 | 9 | ||
| 10 | 10 | assert.throws(() => { | |
| 11 | 11 | dns.lookup(1, {}); | |
| 12 | - }, /^TypeError: Invalid arguments: hostname must be a string or falsey$/); | ||
| 12 | + }, common.expectsError({ | ||
| 13 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 14 | + type: TypeError, | ||
| 15 | + message: /^The "hostname" argument must be one of type string or falsey/ | ||
| 16 | + })); | ||
| 13 | 17 | ||
| 14 | 18 | assert.throws(() => { | |
| 15 | 19 | dns.lookup(false, 'cb'); | |
| 16 | - }, /^TypeError: Invalid arguments: callback must be passed$/); | ||
| 20 | + }, common.expectsError({ | ||
| 21 | + code: 'ERR_INVALID_CALLBACK', | ||
| 22 | + type: TypeError | ||
| 23 | + })); | ||
| 17 | 24 | ||
| 18 | 25 | assert.throws(() => { | |
| 19 | 26 | dns.lookup(false, 'options', 'cb'); | |
| 20 | - }, /^TypeError: Invalid arguments: callback must be passed$/); | ||
| 27 | + }, common.expectsError({ | ||
| 28 | + code: 'ERR_INVALID_CALLBACK', | ||
| 29 | + type: TypeError | ||
| 30 | + })); | ||
| 21 | 31 | ||
| 22 | 32 | assert.throws(() => { | |
| 23 | 33 | dns.lookup(false, { | |
| 24 | 34 | hints: 100, | |
| 25 | 35 | family: 0, | |
| 26 | 36 | all: false | |
| 27 | 37 | }, common.mustNotCall()); | |
| 28 | - }, /^TypeError: Invalid argument: hints must use valid flags$/); | ||
| 38 | + }, common.expectsError({ | ||
| 39 | + code: 'ERR_INVALID_OPT_VALUE', | ||
| 40 | + type: TypeError, | ||
| 41 | + message: 'The value "100" is invalid for option "hints"' | ||
| 42 | + })); | ||
| 29 | 43 | ||
| 30 | 44 | assert.throws(() => { | |
| 31 | 45 | dns.lookup(false, { | |
| 32 | 46 | hints: 0, | |
| 33 | 47 | family: 20, | |
| 34 | 48 | all: false | |
| 35 | 49 | }, common.mustNotCall()); | |
| 36 | - }, /^TypeError: Invalid argument: family must be 4 or 6$/); | ||
| 50 | + }, common.expectsError({ | ||
| 51 | + code: 'ERR_INVALID_OPT_VALUE', | ||
| 52 | + type: TypeError, | ||
| 53 | + message: 'The value "20" is invalid for option "family"' | ||
| 54 | + })); | ||
| 37 | 55 | ||
| 38 | 56 | assert.doesNotThrow(() => { | |
| 39 | 57 | dns.lookup(false, { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,12 +20,19 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | - require('../common'); | ||
| 23 | + const common = require('../common'); | ||
| 24 | 24 | const assert = require('assert'); | |
| 25 | 25 | const dns = require('dns'); | |
| 26 | 26 | ||
| 27 | 27 | // Should not raise assertion error. Issue #7070 | |
| 28 | 28 | assert.throws(() => dns.resolveNs([]), // bad name | |
| 29 | - /^Error: "name" argument must be a string$/); | ||
| 29 | + common.expectsError({ | ||
| 30 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 31 | + type: TypeError, | ||
| 32 | + message: /^The "name" argument must be of type string/ | ||
| 33 | + })); | ||
| 30 | 34 | assert.throws(() => dns.resolveNs(''), // bad callback | |
| 31 | - /^Error: "callback" argument must be a function$/); | ||
| 35 | + common.expectsError({ | ||
| 36 | + code: 'ERR_INVALID_CALLBACK', | ||
| 37 | + type: TypeError | ||
| 38 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,10 +68,16 @@ const goog = [ | |||
| 68 | 68 | ]; | |
| 69 | 69 | assert.doesNotThrow(() => dns.setServers(goog)); | |
| 70 | 70 | assert.deepStrictEqual(dns.getServers(), goog); | |
| 71 | - assert.throws(() => dns.setServers(['foobar']), | ||
| 72 | - /^Error: IP address is not properly formatted: foobar$/); | ||
| 73 | - assert.throws(() => dns.setServers(['127.0.0.1:va']), | ||
| 74 | - /^Error: IP address is not properly formatted: 127\.0\.0\.1:va$/); | ||
| 71 | + assert.throws(() => dns.setServers(['foobar']), common.expectsError({ | ||
| 72 | + code: 'ERR_INVALID_IP_ADDRESS', | ||
| 73 | + type: Error, | ||
| 74 | + message: 'Invalid IP address: foobar' | ||
| 75 | + })); | ||
| 76 | + assert.throws(() => dns.setServers(['127.0.0.1:va']), common.expectsError({ | ||
| 77 | + code: 'ERR_INVALID_IP_ADDRESS', | ||
| 78 | + type: Error, | ||
| 79 | + message: 'Invalid IP address: 127.0.0.1:va' | ||
| 80 | + })); | ||
| 75 | 81 | assert.deepStrictEqual(dns.getServers(), goog); | |
| 76 | 82 | ||
| 77 | 83 | const goog6 = [ | |
@@ -105,12 +111,20 @@ assert.deepStrictEqual(dns.getServers(), []); | |||
| 105 | 111 | ||
| 106 | 112 | assert.throws(() => { | |
| 107 | 113 | dns.resolve('example.com', [], common.mustNotCall()); | |
| 108 | - }, /^TypeError: "rrtype" argument must be a string$/); | ||
| 114 | + }, common.expectsError({ | ||
| 115 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 116 | + type: TypeError, | ||
| 117 | + message: 'The "rrtype" argument must be of type string. ' + | ||
| 118 | + 'Received type object' | ||
| 119 | + })); | ||
| 109 | 120 | ||
| 110 | 121 | // dns.lookup should accept only falsey and string values | |
| 111 | 122 | { | |
| 112 | - const errorReg = | ||
| 113 | - /^TypeError: Invalid arguments: hostname must be a string or falsey$/; | ||
| 123 | + const errorReg = common.expectsError({ | ||
| 124 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 125 | + type: TypeError, | ||
| 126 | + message: /^The "hostname" argument must be one of type string or falsey/ | ||
| 127 | + }, 5); | ||
| 114 | 128 | ||
| 115 | 129 | assert.throws(() => dns.lookup({}, common.mustNotCall()), errorReg); | |
| 116 | 130 | ||
@@ -156,13 +170,21 @@ assert.throws(() => { | |||
| 156 | 170 | assert.throws(() => { | |
| 157 | 171 | dns.lookup('nodejs.org', { hints: (dns.V4MAPPED | dns.ADDRCONFIG) + 1 }, | |
| 158 | 172 | common.mustNotCall()); | |
| 159 | - }, /^TypeError: Invalid argument: hints must use valid flags$/); | ||
| 160 | - | ||
| 161 | - assert.throws(() => dns.lookup('nodejs.org'), | ||
| 162 | - /^TypeError: Invalid arguments: callback must be passed$/); | ||
| 163 | - | ||
| 164 | - assert.throws(() => dns.lookup('nodejs.org', 4), | ||
| 165 | - /^TypeError: Invalid arguments: callback must be passed$/); | ||
| 173 | + }, common.expectsError({ | ||
| 174 | + code: 'ERR_INVALID_OPT_VALUE', | ||
| 175 | + type: TypeError, | ||
| 176 | + message: /The value "\d+" is invalid for option "hints"/ | ||
| 177 | + })); | ||
| 178 | + | ||
| 179 | + assert.throws(() => dns.lookup('nodejs.org'), common.expectsError({ | ||
| 180 | + code: 'ERR_INVALID_CALLBACK', | ||
| 181 | + type: TypeError | ||
| 182 | + })); | ||
| 183 | + | ||
| 184 | + assert.throws(() => dns.lookup('nodejs.org', 4), common.expectsError({ | ||
| 185 | + code: 'ERR_INVALID_CALLBACK', | ||
| 186 | + type: TypeError | ||
| 187 | + })); | ||
| 166 | 188 | ||
| 167 | 189 | assert.doesNotThrow(() => dns.lookup('', { family: 4, hints: 0 }, | |
| 168 | 190 | common.mustCall())); | |
@@ -183,25 +205,43 @@ assert.doesNotThrow(() => { | |||
| 183 | 205 | }, common.mustCall()); | |
| 184 | 206 | }); | |
| 185 | 207 | ||
| 186 | - assert.throws(() => dns.lookupService('0.0.0.0'), | ||
| 187 | - /^Error: Invalid arguments$/); | ||
| 188 | - | ||
| 189 | - assert.throws(() => dns.lookupService('fasdfdsaf', 0, common.mustNotCall()), | ||
| 190 | - /^TypeError: "host" argument needs to be a valid IP address$/); | ||
| 208 | + assert.throws(() => dns.lookupService('0.0.0.0'), common.expectsError({ | ||
| 209 | + code: 'ERR_MISSING_ARGS', | ||
| 210 | + type: TypeError, | ||
| 211 | + message: 'The "host", "port", and "callback" arguments must be specified' | ||
| 212 | + })); | ||
| 191 | 213 | ||
| 214 | + const invalidHost = 'fasdfdsaf'; | ||
| 215 | + assert.throws(() => { | ||
| 216 | + dns.lookupService(invalidHost, 0, common.mustNotCall()); | ||
| 217 | + }, common.expectsError({ | ||
| 218 | + code: 'ERR_INVALID_OPT_VALUE', | ||
| 219 | + type: TypeError, | ||
| 220 | + message: `The value "${invalidHost}" is invalid for option "host"` | ||
| 221 | + })); | ||
| 222 | + | ||
| 223 | + const badPortMsg = common.expectsError({ | ||
| 224 | + code: 'ERR_SOCKET_BAD_PORT', | ||
| 225 | + type: RangeError, | ||
| 226 | + message: 'Port should be > 0 and < 65536' | ||
| 227 | + }, 4); | ||
| 192 | 228 | assert.throws(() => dns.lookupService('0.0.0.0', null, common.mustNotCall()), | |
| 193 | - /^TypeError: "port" should be >= 0 and < 65536, got "null"$/); | ||
| 229 | + badPortMsg); | ||
| 194 | 230 | ||
| 195 | 231 | assert.throws( | |
| 196 | 232 | () => dns.lookupService('0.0.0.0', undefined, common.mustNotCall()), | |
| 197 | - /^TypeError: "port" should be >= 0 and < 65536, got "undefined"$/ | ||
| 233 | + badPortMsg | ||
| 198 | 234 | ); | |
| 199 | 235 | ||
| 200 | 236 | assert.throws(() => dns.lookupService('0.0.0.0', 65538, common.mustNotCall()), | |
| 201 | - /^TypeError: "port" should be >= 0 and < 65536, got "65538"$/); | ||
| 237 | + badPortMsg); | ||
| 202 | 238 | ||
| 203 | 239 | assert.throws(() => dns.lookupService('0.0.0.0', 'test', common.mustNotCall()), | |
| 204 | - /^TypeError: "port" should be >= 0 and < 65536, got "test"$/); | ||
| 240 | + badPortMsg); | ||
| 205 | 241 | ||
| 206 | - assert.throws(() => dns.lookupService('0.0.0.0', 80, null), | ||
| 207 | - /^TypeError: "callback" argument must be a function$/); | ||
| 242 | + assert.throws(() => { | ||
| 243 | + dns.lookupService('0.0.0.0', 80, null); | ||
| 244 | + }, common.expectsError({ | ||
| 245 | + code: 'ERR_INVALID_CALLBACK', | ||
| 246 | + type: TypeError | ||
| 247 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments