File tree Expand file tree Collapse file tree 4 files changed +32
-10
lines changed Expand file tree Collapse file tree 4 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -570,6 +570,13 @@ The `'ERR_ARG_NOT_ITERABLE'` error code is used generically to identify that an
570570iterable argument (i.e. a value that works with ` for...of ` loops) is required,
571571but not provided to a Node.js API.
572572
573+ <a id =" ERR_CONSOLE_WRITABLE_STREAM " ></a >
574+ ### ERR_CONSOLE_WRITABLE_STREAM
575+
576+ The ` ERR_CONSOLE_WRITABLE_STREAM ` error code is thrown when ` Console ` is
577+ instantiated without ` stdout ` stream or when ` stdout ` or ` stderr ` streams
578+ are not writable.
579+
573580<a id =" ERR_INVALID_ARG_TYPE " ></a >
574581### ERR_INVALID_ARG_TYPE
575582
Original file line number Diff line number Diff line change 2121
2222'use strict' ;
2323
24+ const errors = require ( 'internal/errors' ) ;
2425const util = require ( 'util' ) ;
2526
2627function Console ( stdout , stderr , ignoreErrors = true ) {
2728 if ( ! ( this instanceof Console ) ) {
2829 return new Console ( stdout , stderr , ignoreErrors ) ;
2930 }
3031 if ( ! stdout || typeof stdout . write !== 'function' ) {
31- throw new TypeError ( 'Console expects a writable stream instance ' ) ;
32+ throw new errors . TypeError ( 'ERR_CONSOLE_WRITABLE_STREAM' , 'stdout ') ;
3233 }
3334 if ( ! stderr ) {
3435 stderr = stdout ;
3536 } else if ( typeof stderr . write !== 'function' ) {
36- throw new TypeError ( 'Console expects writable stream instances ' ) ;
37+ throw new errors . TypeError ( 'ERR_CONSOLE_WRITABLE_STREAM' , 'stderr ') ;
3738 }
3839
3940 var prop = {
Original file line number Diff line number Diff line change @@ -112,6 +112,8 @@ module.exports = exports = {
112112// Note: Please try to keep these in alphabetical order
113113E ( 'ERR_ARG_NOT_ITERABLE' , '%s must be iterable' ) ;
114114E ( 'ERR_ASSERTION' , ( msg ) => msg ) ;
115+ E ( 'ERR_CONSOLE_WRITABLE_STREAM' ,
116+ ( name ) => `Console expects a writable stream instance for ${ name } ` ) ;
115117E ( 'ERR_INVALID_ARG_TYPE' , invalidArgType ) ;
116118E ( 'ERR_INVALID_CALLBACK' , 'callback must be a function' ) ;
117119E ( 'ERR_INVALID_FILE_URL_HOST' , 'File URL host %s' ) ;
Original file line number Diff line number Diff line change @@ -37,16 +37,28 @@ assert.strictEqual('function', typeof Console);
3737
3838// make sure that the Console constructor throws
3939// when not given a writable stream instance
40- assert . throws ( ( ) => {
41- new Console ( ) ;
42- } , / ^ T y p e E r r o r : C o n s o l e e x p e c t s a w r i t a b l e s t r e a m i n s t a n c e $ / ) ;
40+ assert . throws (
41+ ( ) => { new Console ( ) ; } ,
42+ common . expectsError ( {
43+ code : 'ERR_CONSOLE_WRITABLE_STREAM' ,
44+ type : TypeError ,
45+ message : / s t d o u t /
46+ } )
47+ ) ;
4348
4449// Console constructor should throw if stderr exists but is not writable
45- assert . throws ( ( ) => {
46- out . write = common . noop ;
47- err . write = undefined ;
48- new Console ( out , err ) ;
49- } , / ^ T y p e E r r o r : C o n s o l e e x p e c t s w r i t a b l e s t r e a m i n s t a n c e s $ / ) ;
50+ assert . throws (
51+ ( ) => {
52+ out . write = common . noop ;
53+ err . write = undefined ;
54+ new Console ( out , err ) ;
55+ } ,
56+ common . expectsError ( {
57+ code : 'ERR_CONSOLE_WRITABLE_STREAM' ,
58+ type : TypeError ,
59+ message : / s t d e r r /
60+ } )
61+ ) ;
5062
5163out . write = err . write = ( d ) => { } ;
5264
You can’t perform that action at this time.
0 commit comments