From 4d2d6de1b6b9a50c19bee51715e4ee242d80ffd7 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 18 Mar 2026 07:04:26 +0100 Subject: [PATCH] stream: preserve error over AbortError in pipeline Signed-off-by: marcopiraccini PR-URL: https://github.com/nodejs/node/pull/62113 Fixes: https://github.com/nodejs/node/issues/62089 Reviewed-By: Robert Nagy Reviewed-By: Matteo Collina Reviewed-By: Ethan Arrowood --- lib/internal/streams/pipeline.js | 2 +- test/parallel/test-stream-pipeline.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index ad3f0796875aae..546ff579d8ebbd 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -227,7 +227,7 @@ function pipelineImpl(streams, callback, opts) { } function finishImpl(err, final) { - if (err && (!error || error.code === 'ERR_STREAM_PREMATURE_CLOSE')) { + if (err && (!error || error.code === 'ERR_STREAM_PREMATURE_CLOSE' || error.name === 'AbortError')) { error = err; } diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index 6220bc15365361..8852f24a75050f 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -1749,3 +1749,24 @@ tmpdir.refresh(); assert.deepStrictEqual(err, new Error('booom')); })); } + +{ + // Errors thrown in Readable.map inside pipeline should not be + // swallowed by AbortError when the source is an infinite stream. + pipeline( + new Readable({ read() { this.push('data'); } }), + new Transform({ + readableObjectMode: true, + transform(chunk, encoding, callback) { + this.push({}); + callback(); + }, + }), + (readable) => readable.map(async () => { + throw new Error('Boom!'); + }), + common.mustCall((err) => { + assert.strictEqual(err.message, 'Boom!'); + }), + ); +}