File tree Expand file tree Collapse file tree 6 files changed +54
-2
lines changed Expand file tree Collapse file tree 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
22252225
22262226Returns whether the stream has been read from or cancelled.
22272227
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+
22282241### ` stream.Readable.toWeb(streamReadable) `
22292242
22302243<!-- YAML
Original file line number Diff line number Diff line change @@ -245,10 +245,24 @@ function isDisturbed(stream) {
245245 ) ) ;
246246}
247247
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+
248260module . exports = {
249261 kDestroyed,
250262 isDisturbed,
263+ isErrored,
251264 kIsDisturbed,
265+ kIsErrored,
252266 isClosed,
253267 isDestroyed,
254268 isDuplexNodeStream,
Original file line number Diff line number Diff line change @@ -241,6 +241,10 @@ class ReadableStream {
241241 return this [ kState ] . disturbed ;
242242 }
243243
244+ get [ kIsErrored ] ( ) {
245+ return this [ kState ] . state === 'errored' ;
246+ }
247+
244248 /**
245249 * @readonly
246250 * @type {boolean }
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ const promises = require('stream/promises');
3939
4040const Stream = module . exports = require ( 'internal/streams/legacy' ) . Stream ;
4141Stream . isDisturbed = require ( 'internal/streams/utils' ) . isDisturbed ;
42+ Stream . isErrored = require ( 'internal/streams/utils' ) . isErrored ;
4243Stream . Readable = require ( 'internal/streams/readable' ) ;
4344Stream . Writable = require ( 'internal/streams/writable' ) ;
4445Stream . Duplex = require ( 'internal/streams/duplex' ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22const common = require ( '../common' ) ;
33const assert = require ( 'assert' ) ;
4- const { isDisturbed, Readable } = require ( 'stream' ) ;
4+ const { isDisturbed, isErrored , Readable } = require ( 'stream' ) ;
55
66function noop ( ) { }
77
88function check ( readable , data , fn ) {
99 assert . strictEqual ( readable . readableDidRead , false ) ;
1010 assert . strictEqual ( isDisturbed ( readable ) , false ) ;
11+ assert . strictEqual ( isErrored ( readable ) , false ) ;
1112 if ( data === - 1 ) {
12- readable . on ( 'error' , common . mustCall ( ) ) ;
13+ readable . on ( 'error' , common . mustCall ( ( ) => {
14+ assert . strictEqual ( isErrored ( readable ) , true )
15+ } ) ) ;
1316 readable . on ( 'data' , common . mustNotCall ( ) ) ;
1417 readable . on ( 'end' , common . mustNotCall ( ) ) ;
1518 } else {
Original file line number Diff line number Diff line change @@ -1572,3 +1572,20 @@ class Source {
15721572 isDisturbed ( stream , true ) ;
15731573 } ) ( ) . then ( common . mustCall ( ) ) ;
15741574}
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