Skip to content

Commit b29c36b

Browse files
committed
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: #19754 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 22da2f7 commit b29c36b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

lib/dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function resolver(bindingName) {
229229
req.oncomplete = onresolve;
230230
req.ttl = !!(options && options.ttl);
231231
var err = this._handle[bindingName](req, name);
232-
if (err) throw dnsException(err, bindingName);
232+
if (err) throw dnsException(err, bindingName, name);
233233
return req;
234234
}
235235
Object.defineProperty(query, 'name', { value: bindingName });

lib/internal/errors.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -556,20 +556,20 @@ function exceptionWithHostPort(err, syscall, address, port, additional) {
556556
* @returns {Error}
557557
*/
558558
function dnsException(code, syscall, hostname) {
559-
let message;
560-
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
561-
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
562-
if (code === UV_EAI_MEMORY ||
563-
code === UV_EAI_NODATA ||
564-
code === UV_EAI_NONAME) {
565-
code = 'ENOTFOUND'; // Fabricated error name.
566-
}
567-
if (typeof code === 'string') { // c-ares error code.
568-
message = `${syscall} ${code}${hostname ? ` ${hostname}` : ''}`;
569-
} else { // libuv error number
570-
code = lazyInternalUtil().getSystemErrorName(code);
571-
message = `${syscall} ${code}`;
559+
// If `code` is of type number, it is a libuv error number, else it is a
560+
// c-ares error code.
561+
if (typeof code === 'number') {
562+
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
563+
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
564+
if (code === UV_EAI_MEMORY ||
565+
code === UV_EAI_NODATA ||
566+
code === UV_EAI_NONAME) {
567+
code = 'ENOTFOUND'; // Fabricated error name.
568+
} else {
569+
code = lazyInternalUtil().getSystemErrorName(code);
570+
}
572571
}
572+
const message = `${syscall} ${code}${hostname ? ` ${hostname}` : ''}`;
573573
// eslint-disable-next-line no-restricted-syntax
574574
const ex = new Error(message);
575575
// TODO(joyeecheung): errno is supposed to be a number / err, like in

0 commit comments

Comments
 (0)