Skip to content

Commit 51beb26

Browse files
authored
stream: pass error on legacy destroy
PR-URL: #43519 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7cbcc4f commit 51beb26

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/internal/streams/destroy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function destroyer(stream, err) {
319319
// TODO: Don't lose err?
320320
stream.close();
321321
} else if (err) {
322-
process.nextTick(emitErrorCloseLegacy, stream);
322+
process.nextTick(emitErrorCloseLegacy, stream, err);
323323
} else {
324324
process.nextTick(emitCloseLegacy, stream);
325325
}

test/parallel/test-stream-pipeline.js

+30
Original file line numberDiff line numberDiff line change
@@ -1526,3 +1526,33 @@ const tsp = require('timers/promises');
15261526
assert.strictEqual(val, null);
15271527
}));
15281528
}
1529+
1530+
{
1531+
// Mimics a legacy stream without the .destroy method
1532+
class LegacyWritable extends Stream {
1533+
write(chunk, encoding, callback) {
1534+
callback();
1535+
}
1536+
}
1537+
1538+
const writable = new LegacyWritable();
1539+
writable.on('error', common.mustCall((err) => {
1540+
assert.deepStrictEqual(err, new Error('stop'));
1541+
}));
1542+
1543+
pipeline(
1544+
Readable.from({
1545+
[Symbol.asyncIterator]() {
1546+
return {
1547+
next() {
1548+
return Promise.reject(new Error('stop'));
1549+
}
1550+
};
1551+
}
1552+
}),
1553+
writable,
1554+
common.mustCall((err) => {
1555+
assert.deepStrictEqual(err, new Error('stop'));
1556+
})
1557+
);
1558+
}

0 commit comments

Comments
 (0)