diff --git a/lib/internal/streams/add-abort-signal.js b/lib/internal/streams/add-abort-signal.js index 80814f0936782d..9bcd202ec63c1e 100644 --- a/lib/internal/streams/add-abort-signal.js +++ b/lib/internal/streams/add-abort-signal.js @@ -34,7 +34,7 @@ module.exports.addAbortSignalNoValidate = function(signal, stream) { return stream; } const onAbort = () => { - stream.destroy(new AbortError()); + stream.destroy(new AbortError(undefined, { cause: signal.reason })); }; if (signal.aborted) { onAbort(); diff --git a/lib/internal/streams/duplexify.js b/lib/internal/streams/duplexify.js index a15d97d36a5f6e..6fb4e35bafa099 100644 --- a/lib/internal/streams/duplexify.js +++ b/lib/internal/streams/duplexify.js @@ -214,7 +214,8 @@ function fromAsyncGen(fn) { const { chunk, done, cb } = await _promise; process.nextTick(cb); if (done) return; - if (signal.aborted) throw new AbortError(); + if (signal.aborted) + throw new AbortError(undefined, { cause: signal.reason }); ({ promise, resolve } = createDeferredPromise()); yield chunk; } diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index b70d81e4b4e773..a61b187bf83bbd 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -215,7 +215,9 @@ function eos(stream, options, callback) { // Keep it because cleanup removes it. const endCallback = callback; cleanup(); - endCallback.call(stream, new AbortError()); + endCallback.call( + stream, + new AbortError(undefined, { cause: options.signal.reason })); }; if (options.signal.aborted) { process.nextTick(abort); diff --git a/lib/internal/webstreams/adapters.js b/lib/internal/webstreams/adapters.js index 7718fcc2c6b198..5e01d6eb8eb9dd 100644 --- a/lib/internal/webstreams/adapters.js +++ b/lib/internal/webstreams/adapters.js @@ -122,8 +122,7 @@ function newWritableStreamFromStreamWritable(streamWritable) { const cleanup = finished(streamWritable, (error) => { if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') { - const err = new AbortError(); - err.cause = error; + const err = new AbortError(undefined, { cause: error }); error = err; } @@ -403,8 +402,7 @@ function newReadableStreamFromStreamReadable(streamReadable) { const cleanup = finished(streamReadable, (error) => { if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') { - const err = new AbortError(); - err.cause = error; + const err = new AbortError(undefined, { cause: error }); error = err; }