@@ -7,6 +7,7 @@ const filepath = fixtures.path('x.txt');
77const fd = fs . openSync ( filepath , 'r' ) ;
88const expected = 'xyz\n' ;
99
10+
1011// Error must be thrown with string
1112common . expectsError (
1213 ( ) => fs . read ( fd , expected . length , 0 , 'utf-8' , common . mustNotCall ( ) ) ,
@@ -17,6 +18,39 @@ common.expectsError(
1718 }
1819) ;
1920
21+ [ true , null , undefined , ( ) => { } , { } ] . forEach ( ( value ) => {
22+ common . expectsError ( ( ) => {
23+ fs . read ( value ,
24+ Buffer . allocUnsafe ( expected . length ) ,
25+ 0 ,
26+ expected . length ,
27+ 0 ,
28+ common . mustNotCall ( ) ) ;
29+ } , { code : 'ERR_INVALID_ARG_TYPE' , type : TypeError ,
30+ message : 'The "fd" argument must be of type integer' } ) ;
31+ } ) ;
32+
33+ common . expectsError ( ( ) => {
34+ fs . read ( fd ,
35+ Buffer . allocUnsafe ( expected . length ) ,
36+ - 1 ,
37+ expected . length ,
38+ 0 ,
39+ common . mustNotCall ( ) ) ;
40+ } , { code : 'ERR_OUT_OF_RANGE' , type : RangeError ,
41+ message : 'The value of "offset" is out of range.' } ) ;
42+
43+ common . expectsError ( ( ) => {
44+ fs . read ( fd ,
45+ Buffer . allocUnsafe ( expected . length ) ,
46+ 0 ,
47+ - 1 ,
48+ 0 ,
49+ common . mustNotCall ( ) ) ;
50+ } , { code : 'ERR_OUT_OF_RANGE' , type : RangeError ,
51+ message : 'The value of "length" is out of range.' } ) ;
52+
53+
2054common . expectsError (
2155 ( ) => fs . readSync ( fd , expected . length , 0 , 'utf-8' ) ,
2256 {
@@ -25,3 +59,32 @@ common.expectsError(
2559 message : 'The "buffer" argument must be one of type Buffer or Uint8Array'
2660 }
2761) ;
62+
63+ [ true , null , undefined , ( ) => { } , { } ] . forEach ( ( value ) => {
64+ common . expectsError ( ( ) => {
65+ fs . readSync ( value ,
66+ Buffer . allocUnsafe ( expected . length ) ,
67+ 0 ,
68+ expected . length ,
69+ 0 ) ;
70+ } , { code : 'ERR_INVALID_ARG_TYPE' , type : TypeError ,
71+ message : 'The "fd" argument must be of type integer' } ) ;
72+ } ) ;
73+
74+ common . expectsError ( ( ) => {
75+ fs . readSync ( fd ,
76+ Buffer . allocUnsafe ( expected . length ) ,
77+ - 1 ,
78+ expected . length ,
79+ 0 ) ;
80+ } , { code : 'ERR_OUT_OF_RANGE' , type : RangeError ,
81+ message : 'The value of "offset" is out of range.' } ) ;
82+
83+ common . expectsError ( ( ) => {
84+ fs . readSync ( fd ,
85+ Buffer . allocUnsafe ( expected . length ) ,
86+ 0 ,
87+ - 1 ,
88+ 0 ) ;
89+ } , { code : 'ERR_OUT_OF_RANGE' , type : RangeError ,
90+ message : 'The value of "length" is out of range.' } ) ;
0 commit comments