@@ -68,10 +68,16 @@ const goog = [
6868] ;
6969assert . doesNotThrow ( ( ) => dns . setServers ( goog ) ) ;
7070assert . deepStrictEqual ( dns . getServers ( ) , goog ) ;
71- assert . throws ( ( ) => dns . setServers ( [ 'foobar' ] ) ,
72- / ^ E r r o r : I P a d d r e s s i s n o t p r o p e r l y f o r m a t t e d : f o o b a r $ / ) ;
73- assert . throws ( ( ) => dns . setServers ( [ '127.0.0.1:va' ] ) ,
74- / ^ E r r o r : I P a d d r e s s i s n o t p r o p e r l y f o r m a t t e d : 1 2 7 \. 0 \. 0 \. 1 : v a $ / ) ;
71+ assert . throws ( ( ) => dns . setServers ( [ 'foobar' ] ) , common . expectsError ( {
72+ code : 'ERR_INVALID_IP_ADDRESS' ,
73+ type : Error ,
74+ message : 'Invalid IP address: foobar'
75+ } ) ) ;
76+ assert . throws ( ( ) => dns . setServers ( [ '127.0.0.1:va' ] ) , common . expectsError ( {
77+ code : 'ERR_INVALID_IP_ADDRESS' ,
78+ type : Error ,
79+ message : 'Invalid IP address: 127.0.0.1:va'
80+ } ) ) ;
7581assert . deepStrictEqual ( dns . getServers ( ) , goog ) ;
7682
7783const goog6 = [
@@ -105,12 +111,20 @@ assert.deepStrictEqual(dns.getServers(), []);
105111
106112assert . throws ( ( ) => {
107113 dns . resolve ( 'example.com' , [ ] , common . mustNotCall ( ) ) ;
108- } , / ^ T y p e E r r o r : " r r t y p e " a r g u m e n t m u s t b e a s t r i n g $ / ) ;
114+ } , common . expectsError ( {
115+ code : 'ERR_INVALID_ARG_TYPE' ,
116+ type : TypeError ,
117+ message : 'The "rrtype" argument must be of type string. ' +
118+ 'Received type object'
119+ } ) ) ;
109120
110121// dns.lookup should accept only falsey and string values
111122{
112- const errorReg =
113- / ^ T y p e E r r o r : I n v a l i d a r g u m e n t s : h o s t n a m e m u s t b e a s t r i n g o r f a l s e y $ / ;
123+ const errorReg = common . expectsError ( {
124+ code : 'ERR_INVALID_ARG_TYPE' ,
125+ type : TypeError ,
126+ message : / ^ T h e " h o s t n a m e " a r g u m e n t m u s t b e o n e o f t y p e s t r i n g o r f a l s e y /
127+ } , 5 ) ;
114128
115129 assert . throws ( ( ) => dns . lookup ( { } , common . mustNotCall ( ) ) , errorReg ) ;
116130
@@ -156,13 +170,21 @@ assert.throws(() => {
156170assert . throws ( ( ) => {
157171 dns . lookup ( 'nodejs.org' , { hints : ( dns . V4MAPPED | dns . ADDRCONFIG ) + 1 } ,
158172 common . mustNotCall ( ) ) ;
159- } , / ^ T y p e E r r o r : I n v a l i d a r g u m e n t : h i n t s m u s t u s e v a l i d f l a g s $ / ) ;
160-
161- assert . throws ( ( ) => dns . lookup ( 'nodejs.org' ) ,
162- / ^ T y p e E r r o r : I n v a l i d a r g u m e n t s : c a l l b a c k m u s t b e p a s s e d $ / ) ;
163-
164- assert . throws ( ( ) => dns . lookup ( 'nodejs.org' , 4 ) ,
165- / ^ T y p e E r r o r : I n v a l i d a r g u m e n t s : c a l l b a c k m u s t b e p a s s e d $ / ) ;
173+ } , common . expectsError ( {
174+ code : 'ERR_INVALID_OPT_VALUE' ,
175+ type : TypeError ,
176+ message : / T h e v a l u e " \d + " i s i n v a l i d f o r o p t i o n " h i n t s " /
177+ } ) ) ;
178+
179+ assert . throws ( ( ) => dns . lookup ( 'nodejs.org' ) , common . expectsError ( {
180+ code : 'ERR_INVALID_CALLBACK' ,
181+ type : TypeError
182+ } ) ) ;
183+
184+ assert . throws ( ( ) => dns . lookup ( 'nodejs.org' , 4 ) , common . expectsError ( {
185+ code : 'ERR_INVALID_CALLBACK' ,
186+ type : TypeError
187+ } ) ) ;
166188
167189assert . doesNotThrow ( ( ) => dns . lookup ( '' , { family : 4 , hints : 0 } ,
168190 common . mustCall ( ) ) ) ;
@@ -183,25 +205,43 @@ assert.doesNotThrow(() => {
183205 } , common . mustCall ( ) ) ;
184206} ) ;
185207
186- assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' ) ,
187- / ^ E r r o r : I n v a l i d a r g u m e n t s $ / ) ;
188-
189- assert . throws ( ( ) => dns . lookupService ( 'fasdfdsaf' , 0 , common . mustNotCall ( ) ) ,
190- / ^ T y p e E r r o r : " h o s t " a r g u m e n t n e e d s t o b e a v a l i d I P a d d r e s s $ / ) ;
208+ assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' ) , common . expectsError ( {
209+ code : 'ERR_MISSING_ARGS' ,
210+ type : TypeError ,
211+ message : 'The "host", "port", and "callback" arguments must be specified'
212+ } ) ) ;
191213
214+ const invalidHost = 'fasdfdsaf' ;
215+ assert . throws ( ( ) => {
216+ dns . lookupService ( invalidHost , 0 , common . mustNotCall ( ) ) ;
217+ } , common . expectsError ( {
218+ code : 'ERR_INVALID_OPT_VALUE' ,
219+ type : TypeError ,
220+ message : `The value "${ invalidHost } " is invalid for option "host"`
221+ } ) ) ;
222+
223+ const badPortMsg = common . expectsError ( {
224+ code : 'ERR_SOCKET_BAD_PORT' ,
225+ type : RangeError ,
226+ message : 'Port should be > 0 and < 65536'
227+ } , 4 ) ;
192228assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , null , common . mustNotCall ( ) ) ,
193- / ^ T y p e E r r o r : " p o r t " s h o u l d b e > = 0 a n d < 6 5 5 3 6 , g o t " n u l l " $ / ) ;
229+ badPortMsg ) ;
194230
195231assert . throws (
196232 ( ) => dns . lookupService ( '0.0.0.0' , undefined , common . mustNotCall ( ) ) ,
197- / ^ T y p e E r r o r : " p o r t " s h o u l d b e > = 0 a n d < 6 5 5 3 6 , g o t " u n d e f i n e d " $ /
233+ badPortMsg
198234) ;
199235
200236assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 65538 , common . mustNotCall ( ) ) ,
201- / ^ T y p e E r r o r : " p o r t " s h o u l d b e > = 0 a n d < 6 5 5 3 6 , g o t " 6 5 5 3 8 " $ / ) ;
237+ badPortMsg ) ;
202238
203239assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 'test' , common . mustNotCall ( ) ) ,
204- / ^ T y p e E r r o r : " p o r t " s h o u l d b e > = 0 a n d < 6 5 5 3 6 , g o t " t e s t " $ / ) ;
240+ badPortMsg ) ;
205241
206- assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 80 , null ) ,
207- / ^ T y p e E r r o r : " c a l l b a c k " a r g u m e n t m u s t b e a f u n c t i o n $ / ) ;
242+ assert . throws ( ( ) => {
243+ dns . lookupService ( '0.0.0.0' , 80 , null ) ;
244+ } , common . expectsError ( {
245+ code : 'ERR_INVALID_CALLBACK' ,
246+ type : TypeError
247+ } ) ) ;
0 commit comments