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: #29040Fixes: #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‎

Lines changed: 7 additions & 8 deletions
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-
functionlookupService(hostname,port,callback){
167+
functionlookupService(address,port,callback){
169168
if(arguments.length!==3)
170-
thrownewERR_MISSING_ARGS('hostname','port','callback');
169+
thrownewERR_MISSING_ARGS('address','port','callback');
171170

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

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

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

189-
consterr=cares.getnameinfo(req,hostname,port);
190-
if(err)throwdnsException(err,'getnameinfo',hostname);
188+
consterr=cares.getnameinfo(req,address,port);
189+
if(err)throwdnsException(err,'getnameinfo',address);
191190
returnreq;
192191
}
193192

‎lib/internal/dns/promises.js‎

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

154-
functionlookupService(hostname,port){
154+
functionlookupService(address,port){
155155
if(arguments.length!==2)
156-
thrownewERR_MISSING_ARGS('hostname','port');
156+
thrownewERR_MISSING_ARGS('address','port');
157157

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

161161
if(!isLegalPort(port))
162162
thrownewERR_SOCKET_BAD_PORT(port);
163163

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

167167

‎test/parallel/test-dns.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,29 +265,29 @@ dns.lookup('',{
265265
consterr={
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-
constinvalidHost='fasdfdsaf';
278+
constinvalidAddress='fasdfdsaf';
279279
consterr={
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)