@@ -7,6 +7,7 @@ const filepath = fixtures.path('x.txt');
7
7
const fd = fs . openSync ( filepath , 'r' ) ;
8
8
const expected = 'xyz\n' ;
9
9
10
+
10
11
// Error must be thrown with string
11
12
common . expectsError (
12
13
( ) => fs . read ( fd , expected . length , 0 , 'utf-8' , common . mustNotCall ( ) ) ,
@@ -17,6 +18,39 @@ common.expectsError(
17
18
}
18
19
) ;
19
20
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
+
20
54
common . expectsError (
21
55
( ) => fs . readSync ( fd , expected . length , 0 , 'utf-8' ) ,
22
56
{
@@ -25,3 +59,32 @@ common.expectsError(
25
59
message : 'The "buffer" argument must be one of type Buffer or Uint8Array'
26
60
}
27
61
) ;
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