diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index 24d0b037567e14..9f88e25e153a63 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -204,7 +204,7 @@ function pipelineImpl(streams, callback, opts) { validateAbortSignal(outerSignal, 'options.signal'); function abort() { - finishImpl(new AbortError()); + finishImpl(new AbortError(undefined, { cause: outerSignal?.reason })); } addAbortListener ??= require('internal/events/abort_listener').addAbortListener; diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index 5525fffa46d6d0..339c4c2290b84a 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -1331,12 +1331,13 @@ const tsp = require('timers/promises'); { const ac = new AbortController(); + const reason = new Error('Reason'); const r = Readable.from(async function* () { for (let i = 0; i < 10; i++) { await Promise.resolve(); yield String(i); if (i === 5) { - ac.abort(); + ac.abort(reason); } } }()); @@ -1349,6 +1350,7 @@ const tsp = require('timers/promises'); }); const cb = common.mustCall((err) => { assert.strictEqual(err.name, 'AbortError'); + assert.strictEqual(err.cause, reason); assert.strictEqual(res, '012345'); assert.strictEqual(w.destroyed, true); assert.strictEqual(r.destroyed, true);