Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: fix error handling with async iteration #20329

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/streams/async_iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function onError(iter, err) {
iter[kLastReject] = null;
reject(err);
}
iter.error = err;
iter[kError] = err;
}

function wrapForNext(lastPromise, iter) {
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-stream-readable-async-iterators.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ async function tests() {
readable.destroy(new Error('kaboom'));
})();

await (async function() {
console.log('call next() after error');
const readable = new Readable({
read() {}
});
const iterator = readable[Symbol.asyncIterator]();

const err = new Error('kaboom');
readable.destroy(new Error('kaboom'));
await assert.rejects(iterator.next.bind(iterator), err);
})();

await (async function() {
console.log('read object mode');
const max = 42;
Expand Down