From 7ade6e309d824a4725c8652df13cec579788bc96 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 9 Dec 2021 09:15:12 +0100 Subject: [PATCH 1/6] stream: add isErrored helper Refs: https://github.com/nodejs/undici/pull/1134 --- doc/api/stream.md | 13 ++++++++++++ lib/internal/streams/utils.js | 20 ++++++++++++++++--- lib/internal/webstreams/readablestream.js | 5 +++++ lib/stream.js | 4 +++- test/parallel/test-stream-readable-didRead.js | 7 +++++-- test/parallel/test-whatwg-readablestream.js | 19 +++++++++++++++++- 6 files changed, 61 insertions(+), 7 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 8ca8fb1db5c0f1..5934ceae100e36 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -2225,6 +2225,19 @@ added: v16.8.0 Returns whether the stream has been read from or cancelled. +### `stream.Readable.isErrored(stream)` + + + +> Stability: 1 - Experimental + +* `stream` {stream.Readable|ReadableStream} +* Returns: `boolean` + +Returns whether the stream has been errored. + ### `stream.Readable.toWeb(streamReadable)` > Stability: 1 - Experimental @@ -2236,7 +2236,7 @@ added: v16.8.0 * `stream` {stream.Readable|ReadableStream} * Returns: `boolean` -Returns whether the stream has been errored. +Returns whether the stream has encountered an error. ### `stream.Readable.toWeb(streamReadable)` From 571739e263d5ce2a1d09e386d7327057f5fb2192 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 9 Dec 2021 15:34:19 +0100 Subject: [PATCH 3/6] Update doc/api/stream.md Co-authored-by: mscdex --- doc/api/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 0f8482059790ad..66a419cf02c328 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -2234,7 +2234,7 @@ added: REPLACEME > Stability: 1 - Experimental * `stream` {stream.Readable|ReadableStream} -* Returns: `boolean` +* Returns: {boolean} Returns whether the stream has encountered an error. From e6560603c801477a7171ed9da2b4df7cf40a8ad1 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 9 Dec 2021 15:34:42 +0100 Subject: [PATCH 4/6] Update doc/api/stream.md --- doc/api/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 66a419cf02c328..247eb54126c17f 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -2233,7 +2233,7 @@ added: REPLACEME > Stability: 1 - Experimental -* `stream` {stream.Readable|ReadableStream} +* `stream` {stream.Readable|stream.Writable|stream.Duplex|WritableStream||ReadableStream} * Returns: {boolean} Returns whether the stream has encountered an error. From 44d58f9824a617d6509674cc3c89bc9b2a4dd1cb Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 10 Dec 2021 08:03:17 +0100 Subject: [PATCH 5/6] fixup --- doc/api/stream.md | 2 +- tools/doc/type-parser.mjs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 247eb54126c17f..2b1035f1874aa4 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -2233,7 +2233,7 @@ added: REPLACEME > Stability: 1 - Experimental -* `stream` {stream.Readable|stream.Writable|stream.Duplex|WritableStream||ReadableStream} +* `stream` {Readable|Writable|Duplex|WritableStream|ReadableStream} * Returns: {boolean} Returns whether the stream has encountered an error. diff --git a/tools/doc/type-parser.mjs b/tools/doc/type-parser.mjs index 3cdee188c01e7e..566a1c92030584 100644 --- a/tools/doc/type-parser.mjs +++ b/tools/doc/type-parser.mjs @@ -211,6 +211,10 @@ const customTypesMap = { 'stream.Readable': 'stream.html#class-streamreadable', 'stream.Transform': 'stream.html#class-streamtransform', 'stream.Writable': 'stream.html#class-streamwritable', + 'Duplex': 'stream.html#class-streamduplex', + 'Readable': 'stream.html#class-streamreadable', + 'Transform': 'stream.html#class-streamtransform', + 'Writable': 'stream.html#class-streamwritable', 'Immediate': 'timers.html#class-immediate', 'Timeout': 'timers.html#class-timeout', From bb4e9f01e9eb2214af5c24404e503c7c51d27379 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 16 Dec 2021 11:39:08 +0100 Subject: [PATCH 6/6] fixup --- test/parallel/test-whatwg-readablestream.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-whatwg-readablestream.js b/test/parallel/test-whatwg-readablestream.js index 5bd3e3872aadff..b5cb94d043b59b 100644 --- a/test/parallel/test-whatwg-readablestream.js +++ b/test/parallel/test-whatwg-readablestream.js @@ -1576,16 +1576,15 @@ class Source { { const stream = new ReadableStream({ - start(controller) { + pull: common.mustCall((controller) => { controller.error(new Error()); - }, - pull: common.mustNotCall(), + }), }); const reader = stream.getReader(); (async () => { isErrored(stream, false); - await reader.read(); + await reader.read().catch(common.mustCall()); isErrored(stream, true); })().then(common.mustCall()); }