Skip to content

Commit 4d2d6de

Browse files
stream: preserve error over AbortError in pipeline
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com> PR-URL: #62113 Fixes: #62089 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
1 parent 9fc6b64 commit 4d2d6de

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/internal/streams/pipeline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function pipelineImpl(streams, callback, opts) {
227227
}
228228

229229
function finishImpl(err, final) {
230-
if (err && (!error || error.code === 'ERR_STREAM_PREMATURE_CLOSE')) {
230+
if (err && (!error || error.code === 'ERR_STREAM_PREMATURE_CLOSE' || error.name === 'AbortError')) {
231231
error = err;
232232
}
233233

test/parallel/test-stream-pipeline.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,3 +1749,24 @@ tmpdir.refresh();
17491749
assert.deepStrictEqual(err, new Error('booom'));
17501750
}));
17511751
}
1752+
1753+
{
1754+
// Errors thrown in Readable.map inside pipeline should not be
1755+
// swallowed by AbortError when the source is an infinite stream.
1756+
pipeline(
1757+
new Readable({ read() { this.push('data'); } }),
1758+
new Transform({
1759+
readableObjectMode: true,
1760+
transform(chunk, encoding, callback) {
1761+
this.push({});
1762+
callback();
1763+
},
1764+
}),
1765+
(readable) => readable.map(async () => {
1766+
throw new Error('Boom!');
1767+
}),
1768+
common.mustCall((err) => {
1769+
assert.strictEqual(err.message, 'Boom!');
1770+
}),
1771+
);
1772+
}

0 commit comments

Comments
 (0)