@@ -12,6 +12,7 @@ const {
1212 PromiseReject,
1313 PromiseResolve,
1414 PromiseWithResolvers,
15+ Symbol,
1516 SymbolAsyncDispose,
1617 SymbolAsyncIterator,
1718 SymbolDispose,
@@ -53,6 +54,8 @@ const {
5354 RingBuffer,
5455} = require ( 'internal/streams/iter/ringbuffer' ) ;
5556
57+ const kNoFailReason = Symbol ( 'kNoFailReason' ) ;
58+
5659// =============================================================================
5760// PushQueue - Internal Queue with Chunk-Based Backpressure
5861// =============================================================================
@@ -315,14 +318,16 @@ class PushQueue {
315318 * No-op if errored or closed (fully drained).
316319 * If closing (draining), short-circuits the drain.
317320 */
318- fail ( reason ) {
321+ fail ( reason = kNoFailReason ) {
319322 if ( this . #writerState === 'errored' || this . #writerState === 'closed' ) {
320323 return ;
321324 }
322325
323326 const wasClosing = this . #writerState === 'closing' ;
324327 this . #writerState = 'errored' ;
325- this . #error = reason ?? new ERR_INVALID_STATE ( 'Failed' ) ;
328+ this . #error = reason === kNoFailReason ?
329+ new ERR_INVALID_STATE ( 'Failed' ) :
330+ reason ;
326331 this . #cleanup( ) ;
327332 this . #rejectPendingReads( this . #error) ;
328333 this . #rejectPendingDrains( this . #error) ;
@@ -398,7 +403,7 @@ class PushQueue {
398403 return { __proto__ : null , value : undefined , done : true } ;
399404 }
400405
401- if ( this . #writerState === 'errored' && this . #error ) {
406+ if ( this . #writerState === 'errored' ) {
402407 throw this . #error;
403408 }
404409
@@ -473,7 +478,7 @@ class PushQueue {
473478 } else if ( this . #writerState === 'closed' ) {
474479 const pending = this . #pendingReads. shift ( ) ;
475480 pending . resolve ( { __proto__ : null , value : undefined , done : true } ) ;
476- } else if ( this . #writerState === 'errored' && this . #error ) {
481+ } else if ( this . #writerState === 'errored' ) {
477482 const pending = this . #pendingReads. shift ( ) ;
478483 pending . reject ( this . #error) ;
479484 } else if ( this . #consumerState === 'returned' ) {
@@ -624,7 +629,7 @@ class PushWriter {
624629 }
625630
626631 fail ( reason ) {
627- this . #queue. fail ( reason ) ;
632+ this . #queue. fail ( arguments . length === 0 ? kNoFailReason : reason ) ;
628633 }
629634
630635 [ SymbolAsyncDispose ] ( ) {
0 commit comments