dns: update lookupService() first arg name

The first argument to lookupService() should be an IP address,
and is named "address" in the documentation. This commit updates
the code to match the documentation and provide less confusing
errors.

PR-URL: https://github.com/nodejs/node/pull/29040
Fixes: https://github.com/nodejs/node/issues/29039
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
cjihrig 2019-08-07 21:59:51 -04:00 committed by Rich Trott
parent c146f884a3
commit df936c5925
3 changed files with 18 additions and 19 deletions

View File

@ -164,13 +164,12 @@ function onlookupservice(err, hostname, service) {
} }
// lookupService(address, port, callback) function lookupService(address, port, callback) {
function lookupService(hostname, port, callback) {
if (arguments.length !== 3) if (arguments.length !== 3)
throw new ERR_MISSING_ARGS('hostname', 'port', 'callback'); throw new ERR_MISSING_ARGS('address', 'port', 'callback');
if (isIP(hostname) === 0) if (isIP(address) === 0)
throw new ERR_INVALID_OPT_VALUE('hostname', hostname); throw new ERR_INVALID_OPT_VALUE('address', address);
if (!isLegalPort(port)) if (!isLegalPort(port))
throw new ERR_SOCKET_BAD_PORT(port); throw new ERR_SOCKET_BAD_PORT(port);
@ -182,12 +181,12 @@ function lookupService(hostname, port, callback) {
const req = new GetNameInfoReqWrap(); const req = new GetNameInfoReqWrap();
req.callback = callback; req.callback = callback;
req.hostname = hostname; req.hostname = address;
req.port = port; req.port = port;
req.oncomplete = onlookupservice; req.oncomplete = onlookupservice;
const err = cares.getnameinfo(req, hostname, port); const err = cares.getnameinfo(req, address, port);
if (err) throw dnsException(err, 'getnameinfo', hostname); if (err) throw dnsException(err, 'getnameinfo', address);
return req; return req;
} }

View File

@ -151,17 +151,17 @@ function createLookupServicePromise(hostname, port) {
}); });
} }
function lookupService(hostname, port) { function lookupService(address, port) {
if (arguments.length !== 2) if (arguments.length !== 2)
throw new ERR_MISSING_ARGS('hostname', 'port'); throw new ERR_MISSING_ARGS('address', 'port');
if (isIP(hostname) === 0) if (isIP(address) === 0)
throw new ERR_INVALID_OPT_VALUE('hostname', hostname); throw new ERR_INVALID_OPT_VALUE('address', address);
if (!isLegalPort(port)) if (!isLegalPort(port))
throw new ERR_SOCKET_BAD_PORT(port); throw new ERR_SOCKET_BAD_PORT(port);
return createLookupServicePromise(hostname, +port); return createLookupServicePromise(address, +port);
} }

View File

@ -265,29 +265,29 @@ dns.lookup('', {
const err = { const err = {
code: 'ERR_MISSING_ARGS', code: 'ERR_MISSING_ARGS',
type: TypeError, type: TypeError,
message: 'The "hostname", "port", and "callback" arguments must be ' + message: 'The "address", "port", and "callback" arguments must be ' +
'specified' 'specified'
}; };
common.expectsError(() => dns.lookupService('0.0.0.0'), err); common.expectsError(() => dns.lookupService('0.0.0.0'), err);
err.message = 'The "hostname" and "port" arguments must be specified'; err.message = 'The "address" and "port" arguments must be specified';
common.expectsError(() => dnsPromises.lookupService('0.0.0.0'), err); common.expectsError(() => dnsPromises.lookupService('0.0.0.0'), err);
} }
{ {
const invalidHost = 'fasdfdsaf'; const invalidAddress = 'fasdfdsaf';
const err = { const err = {
code: 'ERR_INVALID_OPT_VALUE', code: 'ERR_INVALID_OPT_VALUE',
type: TypeError, type: TypeError,
message: `The value "${invalidHost}" is invalid for option "hostname"` message: `The value "${invalidAddress}" is invalid for option "address"`
}; };
common.expectsError(() => { common.expectsError(() => {
dnsPromises.lookupService(invalidHost, 0); dnsPromises.lookupService(invalidAddress, 0);
}, err); }, err);
common.expectsError(() => { common.expectsError(() => {
dns.lookupService(invalidHost, 0, common.mustNotCall()); dns.lookupService(invalidAddress, 0, common.mustNotCall());
}, err); }, err);
} }