File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -2554,8 +2554,13 @@ WriteStream.prototype.open = function() {
2554
2554
2555
2555
2556
2556
WriteStream . prototype . _write = function ( data , encoding , cb ) {
2557
- if ( ! ( data instanceof Buffer ) )
2558
- return this . emit ( 'error' , new Error ( 'Invalid data' ) ) ;
2557
+ if ( ! ( data instanceof Buffer ) ) {
2558
+ const err = new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' ,
2559
+ 'data' ,
2560
+ 'Buffer' ,
2561
+ data ) ;
2562
+ return this . emit ( 'error' , err ) ;
2563
+ }
2559
2564
2560
2565
if ( typeof this . fd !== 'number' ) {
2561
2566
return this . once ( 'open' , function ( ) {
Original file line number Diff line number Diff line change @@ -49,3 +49,16 @@ common.refreshTmpDir();
49
49
} ) ;
50
50
stream . destroy ( ) ;
51
51
}
52
+
53
+ // Throws if data is not of type Buffer.
54
+ {
55
+ const stream = fs . createWriteStream ( file ) ;
56
+ common . expectsError ( ( ) => {
57
+ stream . _write ( 42 , null , function ( ) { } ) ;
58
+ } , {
59
+ code : 'ERR_INVALID_ARG_TYPE' ,
60
+ type : TypeError ,
61
+ message : 'The "data" argument must be of type Buffer. Received type number'
62
+ } ) ;
63
+ stream . destroy ( ) ;
64
+ }
You can’t perform that action at this time.
0 commit comments