errors: make dns errors consistent

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: https://github.com/nodejs/node/pull/19754
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater 2018-04-01 07:54:32 +02:00
parent 22da2f731d
commit b29c36b807
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 14 additions and 14 deletions

View File

@ -229,7 +229,7 @@ function resolver(bindingName) {
req.oncomplete = onresolve; req.oncomplete = onresolve;
req.ttl = !!(options && options.ttl); req.ttl = !!(options && options.ttl);
var err = this._handle[bindingName](req, name); var err = this._handle[bindingName](req, name);
if (err) throw dnsException(err, bindingName); if (err) throw dnsException(err, bindingName, name);
return req; return req;
} }
Object.defineProperty(query, 'name', { value: bindingName }); Object.defineProperty(query, 'name', { value: bindingName });

View File

@ -556,20 +556,20 @@ function exceptionWithHostPort(err, syscall, address, port, additional) {
* @returns {Error} * @returns {Error}
*/ */
function dnsException(code, syscall, hostname) { function dnsException(code, syscall, hostname) {
let message; // If `code` is of type number, it is a libuv error number, else it is a
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass // c-ares error code.
// the true error to the user. ENOTFOUND is not even a proper POSIX error! if (typeof code === 'number') {
if (code === UV_EAI_MEMORY || // FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
code === UV_EAI_NODATA || // the true error to the user. ENOTFOUND is not even a proper POSIX error!
code === UV_EAI_NONAME) { if (code === UV_EAI_MEMORY ||
code = 'ENOTFOUND'; // Fabricated error name. code === UV_EAI_NODATA ||
} code === UV_EAI_NONAME) {
if (typeof code === 'string') { // c-ares error code. code = 'ENOTFOUND'; // Fabricated error name.
message = `${syscall} ${code}${hostname ? ` ${hostname}` : ''}`; } else {
} else { // libuv error number code = lazyInternalUtil().getSystemErrorName(code);
code = lazyInternalUtil().getSystemErrorName(code); }
message = `${syscall} ${code}`;
} }
const message = `${syscall} ${code}${hostname ? ` ${hostname}` : ''}`;
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
const ex = new Error(message); const ex = new Error(message);
// TODO(joyeecheung): errno is supposed to be a number / err, like in // TODO(joyeecheung): errno is supposed to be a number / err, like in