@@ -537,34 +537,33 @@ function exceptionWithHostPort(err, syscall, address, port, additional) {
537537}
538538
539539/**
540- * @param {number|string } err - A libuv error number or a c-ares error code
540+ * @param {number|string } code - A libuv error number or a c-ares error code
541541 * @param {string } syscall
542542 * @param {string } [hostname]
543543 * @returns {Error }
544544 */
545- function dnsException ( err , syscall , hostname ) {
546- // eslint-disable-next-line no-restricted-syntax
547- const ex = new Error ( ) ;
545+ function dnsException ( code , syscall , hostname ) {
546+ let message ;
548547 // FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
549548 // the true error to the user. ENOTFOUND is not even a proper POSIX error!
550- if ( err === UV_EAI_MEMORY ||
551- err === UV_EAI_NODATA ||
552- err === UV_EAI_NONAME ) {
553- err = 'ENOTFOUND' ; // Fabricated error name.
549+ if ( code === UV_EAI_MEMORY ||
550+ code === UV_EAI_NODATA ||
551+ code === UV_EAI_NONAME ) {
552+ code = 'ENOTFOUND' ; // Fabricated error name.
554553 }
555- if ( typeof err === 'string' ) { // c-ares error code.
556- const errHost = hostname ? ` ${ hostname } ` : '' ;
557- ex . message = `${ syscall } ${ err } ${ errHost } ` ;
558- // TODO(joyeecheung): errno is supposed to be a number, like in uvException
559- ex . code = ex . errno = err ;
560- ex . syscall = syscall ;
554+ if ( typeof code === 'string' ) { // c-ares error code.
555+ message = `${ syscall } ${ code } ${ hostname ? ` ${ hostname } ` : '' } ` ;
561556 } else { // libuv error number
562- const code = lazyInternalUtil ( ) . getSystemErrorName ( err ) ;
563- ex . message = `${ syscall } ${ code } ` ;
564- // TODO(joyeecheung): errno is supposed to be err, like in uvException
565- ex . code = ex . errno = code ;
566- ex . syscall = syscall ;
557+ code = lazyInternalUtil ( ) . getSystemErrorName ( code ) ;
558+ message = `${ syscall } ${ code } ` ;
567559 }
560+ // eslint-disable-next-line no-restricted-syntax
561+ const ex = new Error ( message ) ;
562+ // TODO(joyeecheung): errno is supposed to be a number / err, like in
563+ // uvException.
564+ ex . errno = code ;
565+ ex . code = code ;
566+ ex . syscall = syscall ;
568567 if ( hostname ) {
569568 ex . hostname = hostname ;
570569 }
0 commit comments