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!'); + }), + ); +}