Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ddc5532
zlib: port errors to new system
targos Feb 27, 2018
def3846
vm: port errors to new system
targos Feb 27, 2018
c0d20ba
v8: port errors to new system
targos Feb 27, 2018
b08cf46
util: port errors to new system
targos Feb 27, 2018
4a314e7
url: port errors to new system
targos Feb 27, 2018
247ddb8
tty: port errors to new system
targos Feb 27, 2018
870cdf0
tls: port: errors to new system
targos Feb 27, 2018
a7aa7bd
timers: port errors to new system
targos Feb 27, 2018
f350861
string_decoder: port errors to new system
targos Feb 27, 2018
82a4d20
repl: port errors to new system
targos Feb 27, 2018
fa70791
readline: port errors to new system
targos Feb 27, 2018
721314e
querystring: port errors to new system
targos Feb 27, 2018
a7df2bc
perf_hooks: port errors to new system
targos Feb 27, 2018
bda8874
path: port errors to new system
targos Feb 27, 2018
530f289
net: port errors to new system
targos Feb 27, 2018
ac2c9c3
module: port errors to new system
targos Feb 27, 2018
d102090
inspector: port errors to new system
targos Feb 27, 2018
0db60be
https: port errors to new system
targos Feb 27, 2018
a6b8a25
fs: port errors to new system
targos Feb 27, 2018
0b226fd
events: port errors to new system
targos Feb 27, 2018
ee6945c
domain: port errors to new system
targos Feb 27, 2018
5eaffd2
dns: port errors to new system
targos Feb 27, 2018
eabb4f6
dgram: port errors to new system
targos Feb 27, 2018
7d14db2
crypto: port errors to new system
targos Feb 27, 2018
e78c0f9
child_process: port errors to new system
targos Feb 27, 2018
bee022b
buffer: port errors to new system
targos Feb 27, 2018
eccd4b0
async_hooks: port errors to new system
targos Feb 27, 2018
dbddf7b
assert: port errors to new system
targos Feb 27, 2018
0d5b4b9
FIXUP: linter
targos Mar 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dns: port errors to new system
  • Loading branch information
targos committed Mar 4, 2018
commit 5eaffd287e0086298f7b181c3ad0ad275642443c
40 changes: 23 additions & 17 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ const cares = process.binding('cares_wrap');
const { isIP, isIPv4, isLegalPort } = require('internal/net');
const { customPromisifyArgs } = require('internal/util');
const errors = require('internal/errors');
const {
ERR_DNS_SET_SERVERS_FAILED,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CALLBACK,
ERR_INVALID_IP_ADDRESS,
ERR_INVALID_OPT_VALUE,
ERR_MISSING_ARGS,
ERR_SOCKET_BAD_PORT
} = errors.codes;

const {
GetAddrInfoReqWrap,
Expand Down Expand Up @@ -76,13 +85,12 @@ function lookup(hostname, options, callback) {

// Parse arguments
if (hostname && typeof hostname !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'hostname',
['string', 'falsy'], hostname);
throw new ERR_INVALID_ARG_TYPE('hostname', ['string', 'falsy'], hostname);
} else if (typeof options === 'function') {
callback = options;
family = 0;
} else if (typeof callback !== 'function') {
throw new errors.TypeError('ERR_INVALID_CALLBACK');
throw new ERR_INVALID_CALLBACK();
} else if (options !== null && typeof options === 'object') {
hints = options.hints >>> 0;
family = options.family >>> 0;
Expand All @@ -93,14 +101,14 @@ function lookup(hostname, options, callback) {
hints !== cares.AI_ADDRCONFIG &&
hints !== cares.AI_V4MAPPED &&
hints !== (cares.AI_ADDRCONFIG | cares.AI_V4MAPPED)) {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'hints', hints);
throw new ERR_INVALID_OPT_VALUE('hints', hints);
}
} else {
family = options >>> 0;
}

if (family !== 0 && family !== 4 && family !== 6)
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'family', family);
throw new ERR_INVALID_OPT_VALUE('family', family);

if (!hostname) {
if (all) {
Expand Down Expand Up @@ -151,16 +159,16 @@ function onlookupservice(err, host, service) {
// lookupService(address, port, callback)
function lookupService(host, port, callback) {
if (arguments.length !== 3)
throw new errors.TypeError('ERR_MISSING_ARGS', 'host', 'port', 'callback');
throw new ERR_MISSING_ARGS('host', 'port', 'callback');

if (isIP(host) === 0)
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'host', host);
throw new ERR_INVALID_OPT_VALUE('host', host);

if (!isLegalPort(port))
throw new errors.RangeError('ERR_SOCKET_BAD_PORT', port);
throw new ERR_SOCKET_BAD_PORT(port);

if (typeof callback !== 'function')
throw new errors.TypeError('ERR_INVALID_CALLBACK');
throw new ERR_INVALID_CALLBACK();

port = +port;

Expand Down Expand Up @@ -209,10 +217,9 @@ function resolver(bindingName) {
}

if (typeof name !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'name',
'string', name);
throw new ERR_INVALID_ARG_TYPE('name', 'string', name);
} else if (typeof callback !== 'function') {
throw new errors.TypeError('ERR_INVALID_CALLBACK');
throw new ERR_INVALID_CALLBACK();
}

var req = new QueryReqWrap();
Expand Down Expand Up @@ -253,14 +260,13 @@ function resolve(hostname, rrtype, callback) {
resolver = resolveMap.A;
callback = rrtype;
} else {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'rrtype',
'string', rrtype);
throw new ERR_INVALID_ARG_TYPE('rrtype', 'string', rrtype);
}

if (typeof resolver === 'function') {
return resolver.call(this, hostname, callback);
} else {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'rrtype', rrtype);
throw new ERR_INVALID_OPT_VALUE('rrtype', rrtype);
}
}

Expand Down Expand Up @@ -310,7 +316,7 @@ function setServers(servers) {
return newSet.push([ipVersion, s, parseInt(p)]);
}

throw new errors.Error('ERR_INVALID_IP_ADDRESS', serv);
throw new ERR_INVALID_IP_ADDRESS.Error(serv);
});

const errorNumber = this._handle.setServers(newSet);
Expand All @@ -320,7 +326,7 @@ function setServers(servers) {
this._handle.setServers(orig.join(','));

var err = cares.strerror(errorNumber);
throw new errors.Error('ERR_DNS_SET_SERVERS_FAILED', err, servers);
throw new ERR_DNS_SET_SERVERS_FAILED(err, servers);
}
}

Expand Down