Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 05b7b8d

Browse filesBrowse files
julien-fMylesBorins
authored andcommitted
stream: fix error handling with async iteration
Fix an issue when an error was emitted by the stream before `iterator.next()` is called. PR-URL: #20329 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
1 parent 348d391 commit 05b7b8d
Copy full SHA for 05b7b8d

File tree

Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/async_iterator.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/async_iterator.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function onError(iter, err) {
5858
iter[kLastReject] = null;
5959
reject(err);
6060
}
61-
iter.error = err;
61+
iter[kError] = err;
6262
}
6363

6464
function wrapForNext(lastPromise, iter) {
Collapse file

‎test/parallel/test-stream-readable-async-iterators.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-readable-async-iterators.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ async function tests() {
115115
readable.destroy(new Error('kaboom'));
116116
})();
117117

118+
await (async function() {
119+
console.log('call next() after error');
120+
const readable = new Readable({
121+
read() {}
122+
});
123+
const iterator = readable[Symbol.asyncIterator]();
124+
125+
const err = new Error('kaboom');
126+
readable.destroy(new Error('kaboom'));
127+
await assert.rejects(iterator.next.bind(iterator), err);
128+
})();
129+
118130
await (async function() {
119131
console.log('read object mode');
120132
const max = 42;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.