Skip to content

Commit

Permalink
errors: make dns errors consistent
Browse files Browse the repository at this point in the history
Right now the hostname could in some cases be missed, depending on
the libuv error number. This makes sure there the hostname is always
added, if available.

PR-URL: #19754
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR committed Apr 5, 2018
1 parent 22da2f7 commit b29c36b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function resolver(bindingName) {
req.oncomplete = onresolve;
req.ttl = !!(options && options.ttl);
var err = this._handle[bindingName](req, name);
if (err) throw dnsException(err, bindingName);
if (err) throw dnsException(err, bindingName, name);
return req;
}
Object.defineProperty(query, 'name', { value: bindingName });
Expand Down
26 changes: 13 additions & 13 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,20 @@ function exceptionWithHostPort(err, syscall, address, port, additional) {
* @returns {Error}
*/
function dnsException(code, syscall, hostname) {
let message;
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
if (code === UV_EAI_MEMORY ||
code === UV_EAI_NODATA ||
code === UV_EAI_NONAME) {
code = 'ENOTFOUND'; // Fabricated error name.
}
if (typeof code === 'string') { // c-ares error code.
message = `${syscall} ${code}${hostname ? ` ${hostname}` : ''}`;
} else { // libuv error number
code = lazyInternalUtil().getSystemErrorName(code);
message = `${syscall} ${code}`;
// If `code` is of type number, it is a libuv error number, else it is a
// c-ares error code.
if (typeof code === 'number') {
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
if (code === UV_EAI_MEMORY ||
code === UV_EAI_NODATA ||
code === UV_EAI_NONAME) {
code = 'ENOTFOUND'; // Fabricated error name.
} else {
code = lazyInternalUtil().getSystemErrorName(code);
}
}
const message = `${syscall} ${code}${hostname ? ` ${hostname}` : ''}`;
// eslint-disable-next-line no-restricted-syntax
const ex = new Error(message);
// TODO(joyeecheung): errno is supposed to be a number / err, like in
Expand Down

0 comments on commit b29c36b

Please sign in to comment.