2121
2222'use strict' ;
2323
24- const util = require ( 'util' ) ;
25-
2624const cares = process . binding ( 'cares_wrap' ) ;
2725const { isLegalPort } = require ( 'internal/net' ) ;
2826const { customPromisifyArgs } = require ( 'internal/util' ) ;
2927const errors = require ( 'internal/errors' ) ;
30- const {
31- UV_EAI_MEMORY ,
32- UV_EAI_NODATA ,
33- UV_EAI_NONAME
34- } = process . binding ( 'uv' ) ;
3528
3629const {
3730 GetAddrInfoReqWrap,
@@ -41,30 +34,6 @@ const {
4134 isIP
4235} = cares ;
4336
44- function errnoException ( err , syscall , hostname ) {
45- // FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
46- // the true error to the user. ENOTFOUND is not even a proper POSIX error!
47- if ( err === UV_EAI_MEMORY ||
48- err === UV_EAI_NODATA ||
49- err === UV_EAI_NONAME ) {
50- err = 'ENOTFOUND' ;
51- }
52- var ex = null ;
53- if ( typeof err === 'string' ) { // c-ares error code.
54- const errHost = hostname ? ` ${ hostname } ` : '' ;
55- ex = new Error ( `${ syscall } ${ err } ${ errHost } ` ) ;
56- ex . code = err ;
57- ex . errno = err ;
58- ex . syscall = syscall ;
59- } else {
60- ex = util . _errnoException ( err , syscall ) ;
61- }
62- if ( hostname ) {
63- ex . hostname = hostname ;
64- }
65- return ex ;
66- }
67-
6837const IANA_DNS_PORT = 53 ;
6938const digits = [
7039 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // 0-15
@@ -91,10 +60,11 @@ function isIPv4(str) {
9160 return ( str . length > 3 && str . charCodeAt ( 3 ) === 46 /*'.'*/ ) ;
9261}
9362
63+ const dnsException = errors . dnsException ;
9464
9565function onlookup ( err , addresses ) {
9666 if ( err ) {
97- return this . callback ( errnoException ( err , 'getaddrinfo' , this . hostname ) ) ;
67+ return this . callback ( dnsException ( err , 'getaddrinfo' , this . hostname ) ) ;
9868 }
9969 if ( this . family ) {
10070 this . callback ( null , addresses [ 0 ] , this . family ) ;
@@ -106,7 +76,7 @@ function onlookup(err, addresses) {
10676
10777function onlookupall ( err , addresses ) {
10878 if ( err ) {
109- return this . callback ( errnoException ( err , 'getaddrinfo' , this . hostname ) ) ;
79+ return this . callback ( dnsException ( err , 'getaddrinfo' , this . hostname ) ) ;
11080 }
11181
11282 var family = this . family ;
@@ -186,7 +156,7 @@ function lookup(hostname, options, callback) {
186156
187157 var err = cares . getaddrinfo ( req , hostname , family , hints , verbatim ) ;
188158 if ( err ) {
189- process . nextTick ( callback , errnoException ( err , 'getaddrinfo' , hostname ) ) ;
159+ process . nextTick ( callback , dnsException ( err , 'getaddrinfo' , hostname ) ) ;
190160 return { } ;
191161 }
192162 return req ;
@@ -198,7 +168,7 @@ Object.defineProperty(lookup, customPromisifyArgs,
198168
199169function onlookupservice ( err , host , service ) {
200170 if ( err )
201- return this . callback ( errnoException ( err , 'getnameinfo' , this . host ) ) ;
171+ return this . callback ( dnsException ( err , 'getnameinfo' , this . host ) ) ;
202172
203173 this . callback ( null , host , service ) ;
204174}
@@ -227,7 +197,7 @@ function lookupService(host, port, callback) {
227197 req . oncomplete = onlookupservice ;
228198
229199 var err = cares . getnameinfo ( req , host , port ) ;
230- if ( err ) throw errnoException ( err , 'getnameinfo' , host ) ;
200+ if ( err ) throw dnsException ( err , 'getnameinfo' , host ) ;
231201 return req ;
232202}
233203
@@ -240,7 +210,7 @@ function onresolve(err, result, ttls) {
240210 result = result . map ( ( address , index ) => ( { address, ttl : ttls [ index ] } ) ) ;
241211
242212 if ( err )
243- this . callback ( errnoException ( err , this . bindingName , this . hostname ) ) ;
213+ this . callback ( dnsException ( err , this . bindingName , this . hostname ) ) ;
244214 else
245215 this . callback ( null , result ) ;
246216}
@@ -278,7 +248,7 @@ function resolver(bindingName) {
278248 req . oncomplete = onresolve ;
279249 req . ttl = ! ! ( options && options . ttl ) ;
280250 var err = this . _handle [ bindingName ] ( req , name ) ;
281- if ( err ) throw errnoException ( err , bindingName ) ;
251+ if ( err ) throw dnsException ( err , bindingName ) ;
282252 return req ;
283253 }
284254 Object . defineProperty ( query , 'name' , { value : bindingName } ) ;
0 commit comments