Skip to content

Commit 758a17f

Browse files
committed
dns: return TypeError on invalid resolve() input
Synchronize the argument list for `dns.resolve()` with what's in the documentation. Improve the error for a bad `rrtype` to be a `TypeError` rather than an `Error`. PR-URL: #13090 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent a94b98e commit 758a17f

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

lib/dns.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -291,22 +291,21 @@ resolveMap.NAPTR = resolver('queryNaptr');
291291
resolveMap.SOA = resolver('querySoa');
292292

293293

294-
function resolve(hostname, type_, callback_) {
295-
var resolver, callback;
296-
if (typeof type_ === 'string') {
297-
resolver = resolveMap[type_];
298-
callback = callback_;
299-
} else if (typeof type_ === 'function') {
294+
function resolve(hostname, rrtype, callback) {
295+
var resolver;
296+
if (typeof rrtype === 'string') {
297+
resolver = resolveMap[rrtype];
298+
} else if (typeof rrtype === 'function') {
300299
resolver = resolveMap.A;
301-
callback = type_;
300+
callback = rrtype;
302301
} else {
303-
throw new Error('"type" argument must be a string');
302+
throw new TypeError('"rrtype" argument must be a string');
304303
}
305304

306305
if (typeof resolver === 'function') {
307306
return resolver(hostname, callback);
308307
} else {
309-
throw new Error(`Unknown type "${type_}"`);
308+
throw new Error(`Unknown type "${rrtype}"`);
310309
}
311310
}
312311

test/parallel/test-dns.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ assert.doesNotThrow(() => dns.setServers([]));
9191
assert.deepStrictEqual(dns.getServers(), []);
9292

9393
assert.throws(() => {
94-
dns.resolve('test.com', [], common.mustNotCall());
95-
}, function(err) {
96-
return !(err instanceof TypeError);
97-
}, 'Unexpected error');
94+
dns.resolve('example.com', [], common.mustNotCall());
95+
}, /^TypeError: "rrtype" argument must be a string$/);
9896

9997
// dns.lookup should accept only falsey and string values
10098
{

0 commit comments

Comments
 (0)