Skip to content

Commit 05b7b8d

Browse 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 <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent 348d391 commit 05b7b8d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/internal/streams/async_iterator.js

+1-1
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) {

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

+12
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)