File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -350,11 +350,13 @@ function validateLen(len) {
350
350
let err ;
351
351
352
352
if ( ! isInt32 ( len ) ) {
353
- if ( typeof value !== 'number' ) {
353
+ if ( typeof len !== 'number' ) {
354
354
err = new ERR_INVALID_ARG_TYPE ( 'len' , 'number' , len ) ;
355
- } else {
356
- // TODO(BridgeAR): Improve this error message.
355
+ } else if ( ! Number . isInteger ( len ) ) {
357
356
err = new ERR_OUT_OF_RANGE ( 'len' , 'an integer' , len ) ;
357
+ } else {
358
+ // 2 ** 31 === 2147483648
359
+ err = new ERR_OUT_OF_RANGE ( 'len' , '> -2147483649 && < 2147483648' , len ) ;
358
360
}
359
361
}
360
362
Original file line number Diff line number Diff line change @@ -190,6 +190,31 @@ function testFtruncate(cb) {
190
190
) ;
191
191
} ) ;
192
192
193
+ [ - 1.5 , 1.5 ] . forEach ( ( input ) => {
194
+ assert . throws (
195
+ ( ) => fs . ftruncate ( fd , input ) ,
196
+ {
197
+ code : 'ERR_OUT_OF_RANGE' ,
198
+ name : 'RangeError [ERR_OUT_OF_RANGE]' ,
199
+ message : 'The value of "len" is out of range. It must be ' +
200
+ `an integer. Received ${ input } `
201
+ }
202
+ ) ;
203
+ } ) ;
204
+
205
+ // 2 ** 31 = 2147483648
206
+ [ 2147483648 , - 2147483649 ] . forEach ( ( input ) => {
207
+ assert . throws (
208
+ ( ) => fs . ftruncate ( fd , input ) ,
209
+ {
210
+ code : 'ERR_OUT_OF_RANGE' ,
211
+ name : 'RangeError [ERR_OUT_OF_RANGE]' ,
212
+ message : 'The value of "len" is out of range. It must be ' +
213
+ `> -2147483649 && < 2147483648. Received ${ input } `
214
+ }
215
+ ) ;
216
+ } ) ;
217
+
193
218
fs . ftruncate ( fd , undefined , common . mustCall ( function ( err ) {
194
219
assert . ifError ( err ) ;
195
220
assert ( fs . readFileSync ( file5 ) . equals ( Buffer . from ( '' ) ) ) ;
You can’t perform that action at this time.
0 commit comments