From 10be672884552d90d81d21321b09c47bf07729aa Mon Sep 17 00:00:00 2001 From: greguz Date: Tue, 21 Jun 2022 11:02:00 +0200 Subject: [PATCH 1/2] stream: pass error on legacy destroy --- lib/internal/streams/destroy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/streams/destroy.js b/lib/internal/streams/destroy.js index 10f5471e21d3eb..5c352135dc3012 100644 --- a/lib/internal/streams/destroy.js +++ b/lib/internal/streams/destroy.js @@ -319,7 +319,7 @@ function destroyer(stream, err) { // TODO: Don't lose err? stream.close(); } else if (err) { - process.nextTick(emitErrorCloseLegacy, stream); + process.nextTick(emitErrorCloseLegacy, stream, err); } else { process.nextTick(emitCloseLegacy, stream); } From fa5c436b576ee7f278829f65cb8797fbd233cae0 Mon Sep 17 00:00:00 2001 From: greguz Date: Tue, 21 Jun 2022 14:50:05 +0200 Subject: [PATCH 2/2] stream: test legacy error event --- test/parallel/test-stream-pipeline.js | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index eecf836b5bb77f..529b18386e25a6 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -1526,3 +1526,33 @@ const tsp = require('timers/promises'); assert.strictEqual(val, null); })); } + +{ + // Mimics a legacy stream without the .destroy method + class LegacyWritable extends Stream { + write(chunk, encoding, callback) { + callback(); + } + } + + const writable = new LegacyWritable(); + writable.on('error', common.mustCall((err) => { + assert.deepStrictEqual(err, new Error('stop')); + })); + + pipeline( + Readable.from({ + [Symbol.asyncIterator]() { + return { + next() { + return Promise.reject(new Error('stop')); + } + }; + } + }), + writable, + common.mustCall((err) => { + assert.deepStrictEqual(err, new Error('stop')); + }) + ); +}