Skip to content

dns: synchronize resolve() docs and code #13090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 8 additions & 9 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,21 @@ resolveMap.NAPTR = resolver('queryNaptr');
resolveMap.SOA = resolver('querySoa');


function resolve(hostname, type_, callback_) {
var resolver, callback;
if (typeof type_ === 'string') {
resolver = resolveMap[type_];
callback = callback_;
} else if (typeof type_ === 'function') {
function resolve(hostname, rrtype, callback) {
var resolver;
if (typeof rrtype === 'string') {
resolver = resolveMap[rrtype];
} else if (typeof rrtype === 'function') {
resolver = resolveMap.A;
callback = type_;
callback = rrtype;
} else {
throw new Error('"type" argument must be a string');
throw new TypeError('"rrtype" argument must be a string');
}

if (typeof resolver === 'function') {
return resolver(hostname, callback);
} else {
throw new Error(`Unknown type "${type_}"`);
throw new Error(`Unknown type "${rrtype}"`);
}
}

Expand Down
6 changes: 2 additions & 4 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ assert.doesNotThrow(() => dns.setServers([]));
assert.deepStrictEqual(dns.getServers(), []);

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

// dns.lookup should accept only falsey and string values
{
Expand Down