Skip to content

Commit 6f7b561

Browse files
cjihrigtargos
authored andcommitted
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: #29040 Fixes: #29039 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent e3b1243 commit 6f7b561

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

lib/dns.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,12 @@ function onlookupservice(err, hostname, service) {
164164
}
165165

166166

167-
// lookupService(address, port, callback)
168-
function lookupService(hostname, port, callback) {
167+
function lookupService(address, port, callback) {
169168
if (arguments.length !== 3)
170-
throw new ERR_MISSING_ARGS('hostname', 'port', 'callback');
169+
throw new ERR_MISSING_ARGS('address', 'port', 'callback');
171170

172-
if (isIP(hostname) === 0)
173-
throw new ERR_INVALID_OPT_VALUE('hostname', hostname);
171+
if (isIP(address) === 0)
172+
throw new ERR_INVALID_OPT_VALUE('address', address);
174173

175174
if (!isLegalPort(port))
176175
throw new ERR_SOCKET_BAD_PORT(port);
@@ -182,12 +181,12 @@ function lookupService(hostname, port, callback) {
182181

183182
const req = new GetNameInfoReqWrap();
184183
req.callback = callback;
185-
req.hostname = hostname;
184+
req.hostname = address;
186185
req.port = port;
187186
req.oncomplete = onlookupservice;
188187

189-
const err = cares.getnameinfo(req, hostname, port);
190-
if (err) throw dnsException(err, 'getnameinfo', hostname);
188+
const err = cares.getnameinfo(req, address, port);
189+
if (err) throw dnsException(err, 'getnameinfo', address);
191190
return req;
192191
}
193192

lib/internal/dns/promises.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ function createLookupServicePromise(hostname, port) {
151151
});
152152
}
153153

154-
function lookupService(hostname, port) {
154+
function lookupService(address, port) {
155155
if (arguments.length !== 2)
156-
throw new ERR_MISSING_ARGS('hostname', 'port');
156+
throw new ERR_MISSING_ARGS('address', 'port');
157157

158-
if (isIP(hostname) === 0)
159-
throw new ERR_INVALID_OPT_VALUE('hostname', hostname);
158+
if (isIP(address) === 0)
159+
throw new ERR_INVALID_OPT_VALUE('address', address);
160160

161161
if (!isLegalPort(port))
162162
throw new ERR_SOCKET_BAD_PORT(port);
163163

164-
return createLookupServicePromise(hostname, +port);
164+
return createLookupServicePromise(address, +port);
165165
}
166166

167167

test/parallel/test-dns.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -265,29 +265,29 @@ dns.lookup('', {
265265
const err = {
266266
code: 'ERR_MISSING_ARGS',
267267
type: TypeError,
268-
message: 'The "hostname", "port", and "callback" arguments must be ' +
268+
message: 'The "address", "port", and "callback" arguments must be ' +
269269
'specified'
270270
};
271271

272272
common.expectsError(() => dns.lookupService('0.0.0.0'), err);
273-
err.message = 'The "hostname" and "port" arguments must be specified';
273+
err.message = 'The "address" and "port" arguments must be specified';
274274
common.expectsError(() => dnsPromises.lookupService('0.0.0.0'), err);
275275
}
276276

277277
{
278-
const invalidHost = 'fasdfdsaf';
278+
const invalidAddress = 'fasdfdsaf';
279279
const err = {
280280
code: 'ERR_INVALID_OPT_VALUE',
281281
type: TypeError,
282-
message: `The value "${invalidHost}" is invalid for option "hostname"`
282+
message: `The value "${invalidAddress}" is invalid for option "address"`
283283
};
284284

285285
common.expectsError(() => {
286-
dnsPromises.lookupService(invalidHost, 0);
286+
dnsPromises.lookupService(invalidAddress, 0);
287287
}, err);
288288

289289
common.expectsError(() => {
290-
dns.lookupService(invalidHost, 0, common.mustNotCall());
290+
dns.lookupService(invalidAddress, 0, common.mustNotCall());
291291
}, err);
292292
}
293293

0 commit comments

Comments
 (0)