File tree 4 files changed +32
-10
lines changed
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
570
570
iterable argument (i.e. a value that works with ` for...of ` loops) is required,
571
571
but not provided to a Node.js API.
572
572
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
+
573
580
<a id =" ERR_INVALID_ARG_TYPE " ></a >
574
581
### ERR_INVALID_ARG_TYPE
575
582
Original file line number Diff line number Diff line change 21
21
22
22
'use strict' ;
23
23
24
+ const errors = require ( 'internal/errors' ) ;
24
25
const util = require ( 'util' ) ;
25
26
26
27
function Console ( stdout , stderr , ignoreErrors = true ) {
27
28
if ( ! ( this instanceof Console ) ) {
28
29
return new Console ( stdout , stderr , ignoreErrors ) ;
29
30
}
30
31
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 ') ;
32
33
}
33
34
if ( ! stderr ) {
34
35
stderr = stdout ;
35
36
} 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 ') ;
37
38
}
38
39
39
40
var prop = {
Original file line number Diff line number Diff line change @@ -112,6 +112,8 @@ module.exports = exports = {
112
112
// Note: Please try to keep these in alphabetical order
113
113
E ( 'ERR_ARG_NOT_ITERABLE' , '%s must be iterable' ) ;
114
114
E ( 'ERR_ASSERTION' , ( msg ) => msg ) ;
115
+ E ( 'ERR_CONSOLE_WRITABLE_STREAM' ,
116
+ ( name ) => `Console expects a writable stream instance for ${ name } ` ) ;
115
117
E ( 'ERR_INVALID_ARG_TYPE' , invalidArgType ) ;
116
118
E ( 'ERR_INVALID_CALLBACK' , 'callback must be a function' ) ;
117
119
E ( '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);
37
37
38
38
// make sure that the Console constructor throws
39
39
// 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
+ ) ;
43
48
44
49
// 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
+ ) ;
50
62
51
63
out . write = err . write = ( d ) => { } ;
52
64
You can’t perform that action at this time.
0 commit comments