Skip to content

Commit a581189

Browse files
stream: preserve error over AbortError in pipeline
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
1 parent c9d0ef8 commit a581189

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,3 +1749,35 @@ 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+
function createInfiniteReadable() {
1757+
return new Readable({
1758+
read() {
1759+
this.push('data');
1760+
},
1761+
});
1762+
}
1763+
1764+
function createObjectTransform() {
1765+
return new Transform({
1766+
readableObjectMode: true,
1767+
transform(chunk, encoding, callback) {
1768+
this.push({});
1769+
callback();
1770+
},
1771+
});
1772+
}
1773+
1774+
pipelinep(
1775+
createInfiniteReadable(),
1776+
createObjectTransform(),
1777+
(readable) => readable.map(async () => {
1778+
throw new Error('Boom!');
1779+
}),
1780+
).then(common.mustNotCall(), common.mustCall((err) => {
1781+
assert.strictEqual(err.message, 'Boom!');
1782+
}));
1783+
}

0 commit comments

Comments
 (0)