Skip to content

Commit

Permalink
dns: pass err to callback instead of throwing
Browse files Browse the repository at this point in the history
Previously, if invalid input is passed to dns methods like dns.reverse,
an error would be thrown. This change instead passes the error to the
callback.

Fixes: nodejs#3882
Fixes: nodejs#3112
  • Loading branch information
evanlucas committed Nov 25, 2015
1 parent ab25589 commit c684932
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ function resolver(bindingName) {
req.hostname = name;
req.oncomplete = onresolve;
var err = binding(req, name);
if (err) throw errnoException(err, bindingName);
if (err)
return callback(errnoException(err, bindingName));
callback.immediately = true;
return req;
};
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ assert.doesNotThrow(function() {
dns.lookup(NaN, noop);
});

// Make sure that dns.reverse does not throw if ip is invalid
assert.doesNotThrow(function() {
dns.reverse('foo', noop)
});

/*
* Make sure that dns.lookup throws if hints does not represent a valid flag.
* (dns.V4MAPPED | dns.ADDRCONFIG) + 1 is invalid because:
Expand Down

0 comments on commit c684932

Please sign in to comment.