21
21
22
22
'use strict' ;
23
23
24
- const util = require ( 'util' ) ;
25
-
26
24
const cares = process . binding ( 'cares_wrap' ) ;
27
25
const { isLegalPort } = require ( 'internal/net' ) ;
28
26
const { customPromisifyArgs } = require ( 'internal/util' ) ;
29
27
const errors = require ( 'internal/errors' ) ;
30
- const {
31
- UV_EAI_MEMORY ,
32
- UV_EAI_NODATA ,
33
- UV_EAI_NONAME
34
- } = process . binding ( 'uv' ) ;
35
28
36
29
const {
37
30
GetAddrInfoReqWrap,
@@ -41,30 +34,6 @@ const {
41
34
isIP
42
35
} = cares ;
43
36
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
-
68
37
const IANA_DNS_PORT = 53 ;
69
38
const digits = [
70
39
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) {
91
60
return ( str . length > 3 && str . charCodeAt ( 3 ) === 46 /*'.'*/ ) ;
92
61
}
93
62
63
+ const dnsException = errors . dnsException ;
94
64
95
65
function onlookup ( err , addresses ) {
96
66
if ( err ) {
97
- return this . callback ( errnoException ( err , 'getaddrinfo' , this . hostname ) ) ;
67
+ return this . callback ( dnsException ( err , 'getaddrinfo' , this . hostname ) ) ;
98
68
}
99
69
if ( this . family ) {
100
70
this . callback ( null , addresses [ 0 ] , this . family ) ;
@@ -106,7 +76,7 @@ function onlookup(err, addresses) {
106
76
107
77
function onlookupall ( err , addresses ) {
108
78
if ( err ) {
109
- return this . callback ( errnoException ( err , 'getaddrinfo' , this . hostname ) ) ;
79
+ return this . callback ( dnsException ( err , 'getaddrinfo' , this . hostname ) ) ;
110
80
}
111
81
112
82
var family = this . family ;
@@ -186,7 +156,7 @@ function lookup(hostname, options, callback) {
186
156
187
157
var err = cares . getaddrinfo ( req , hostname , family , hints , verbatim ) ;
188
158
if ( err ) {
189
- process . nextTick ( callback , errnoException ( err , 'getaddrinfo' , hostname ) ) ;
159
+ process . nextTick ( callback , dnsException ( err , 'getaddrinfo' , hostname ) ) ;
190
160
return { } ;
191
161
}
192
162
return req ;
@@ -198,7 +168,7 @@ Object.defineProperty(lookup, customPromisifyArgs,
198
168
199
169
function onlookupservice ( err , host , service ) {
200
170
if ( err )
201
- return this . callback ( errnoException ( err , 'getnameinfo' , this . host ) ) ;
171
+ return this . callback ( dnsException ( err , 'getnameinfo' , this . host ) ) ;
202
172
203
173
this . callback ( null , host , service ) ;
204
174
}
@@ -227,7 +197,7 @@ function lookupService(host, port, callback) {
227
197
req . oncomplete = onlookupservice ;
228
198
229
199
var err = cares . getnameinfo ( req , host , port ) ;
230
- if ( err ) throw errnoException ( err , 'getnameinfo' , host ) ;
200
+ if ( err ) throw dnsException ( err , 'getnameinfo' , host ) ;
231
201
return req ;
232
202
}
233
203
@@ -240,7 +210,7 @@ function onresolve(err, result, ttls) {
240
210
result = result . map ( ( address , index ) => ( { address, ttl : ttls [ index ] } ) ) ;
241
211
242
212
if ( err )
243
- this . callback ( errnoException ( err , this . bindingName , this . hostname ) ) ;
213
+ this . callback ( dnsException ( err , this . bindingName , this . hostname ) ) ;
244
214
else
245
215
this . callback ( null , result ) ;
246
216
}
@@ -278,7 +248,7 @@ function resolver(bindingName) {
278
248
req . oncomplete = onresolve ;
279
249
req . ttl = ! ! ( options && options . ttl ) ;
280
250
var err = this . _handle [ bindingName ] ( req , name ) ;
281
- if ( err ) throw errnoException ( err , bindingName ) ;
251
+ if ( err ) throw dnsException ( err , bindingName ) ;
282
252
return req ;
283
253
}
284
254
Object . defineProperty ( query , 'name' , { value : bindingName } ) ;
0 commit comments