File tree 6 files changed +54
-2
lines changed
6 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -2225,6 +2225,19 @@ added: v16.8.0
2225
2225
2226
2226
Returns whether the stream has been read from or cancelled.
2227
2227
2228
+ ### ` stream.Readable.isErrored(stream) `
2229
+
2230
+ <!-- YAML
2231
+ added: v16.8.0
2232
+ -->
2233
+
2234
+ > Stability: 1 - Experimental
2235
+
2236
+ * ` stream ` {stream.Readable|ReadableStream}
2237
+ * Returns: ` boolean `
2238
+
2239
+ Returns whether the stream has been errored.
2240
+
2228
2241
### ` stream.Readable.toWeb(streamReadable) `
2229
2242
2230
2243
<!-- YAML
Original file line number Diff line number Diff line change @@ -245,10 +245,24 @@ function isDisturbed(stream) {
245
245
) ) ;
246
246
}
247
247
248
+ function isErrored ( stream ) {
249
+ return ! ! ( stream && (
250
+ stream . readableErrored ||
251
+ stream . writableErrored ||
252
+ stream . _readableState ?. errorEmitted ||
253
+ stream . _writableState ?. errorEmitted ||
254
+ stream . _readableState ?. errored ||
255
+ stream . _writableState ?. errored ||
256
+ stream [ kIsErrored ]
257
+ ) ) ;
258
+ }
259
+
248
260
module . exports = {
249
261
kDestroyed,
250
262
isDisturbed,
263
+ isErrored,
251
264
kIsDisturbed,
265
+ kIsErrored,
252
266
isClosed,
253
267
isDestroyed,
254
268
isDuplexNodeStream,
Original file line number Diff line number Diff line change @@ -241,6 +241,10 @@ class ReadableStream {
241
241
return this [ kState ] . disturbed ;
242
242
}
243
243
244
+ get [ kIsErrored ] ( ) {
245
+ return this [ kState ] . state === 'errored' ;
246
+ }
247
+
244
248
/**
245
249
* @readonly
246
250
* @type {boolean }
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ const promises = require('stream/promises');
39
39
40
40
const Stream = module . exports = require ( 'internal/streams/legacy' ) . Stream ;
41
41
Stream . isDisturbed = require ( 'internal/streams/utils' ) . isDisturbed ;
42
+ Stream . isErrored = require ( 'internal/streams/utils' ) . isErrored ;
42
43
Stream . Readable = require ( 'internal/streams/readable' ) ;
43
44
Stream . Writable = require ( 'internal/streams/writable' ) ;
44
45
Stream . Duplex = require ( 'internal/streams/duplex' ) ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
const common = require ( '../common' ) ;
3
3
const assert = require ( 'assert' ) ;
4
- const { isDisturbed, Readable } = require ( 'stream' ) ;
4
+ const { isDisturbed, isErrored , Readable } = require ( 'stream' ) ;
5
5
6
6
function noop ( ) { }
7
7
8
8
function check ( readable , data , fn ) {
9
9
assert . strictEqual ( readable . readableDidRead , false ) ;
10
10
assert . strictEqual ( isDisturbed ( readable ) , false ) ;
11
+ assert . strictEqual ( isErrored ( readable ) , false ) ;
11
12
if ( data === - 1 ) {
12
- readable . on ( 'error' , common . mustCall ( ) ) ;
13
+ readable . on ( 'error' , common . mustCall ( ( ) => {
14
+ assert . strictEqual ( isErrored ( readable ) , true )
15
+ } ) ) ;
13
16
readable . on ( 'data' , common . mustNotCall ( ) ) ;
14
17
readable . on ( 'end' , common . mustNotCall ( ) ) ;
15
18
} else {
Original file line number Diff line number Diff line change @@ -1572,3 +1572,20 @@ class Source {
1572
1572
isDisturbed ( stream , true ) ;
1573
1573
} ) ( ) . then ( common . mustCall ( ) ) ;
1574
1574
}
1575
+
1576
+
1577
+ {
1578
+ const stream = new ReadableStream ( {
1579
+ start ( controller ) {
1580
+ controller . error ( new Error ( ) ) ;
1581
+ } ,
1582
+ pull : common . mustNotCall ( ) ,
1583
+ } ) ;
1584
+
1585
+ const reader = stream . getReader ( ) ;
1586
+ ( async ( ) => {
1587
+ isErrored ( stream , false ) ;
1588
+ await reader . read ( ) ;
1589
+ isErrored ( stream , true ) ;
1590
+ } ) ( ) . then ( common . mustCall ( ) ) ;
1591
+ }
You can’t perform that action at this time.
0 commit comments