From 046debaee0ca0073c3d76102c0396f2ff3181bc6 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 28 Nov 2021 12:45:48 -0800 Subject: [PATCH] stream: use cause options in AbortError constructors Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/41008 Reviewed-By: Ruben Bridgewater Reviewed-By: Robert Nagy Reviewed-By: Benjamin Gruenbaum --- lib/internal/streams/add-abort-signal.js | 2 +- lib/internal/streams/duplexify.js | 3 ++- lib/internal/streams/end-of-stream.js | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/internal/streams/add-abort-signal.js b/lib/internal/streams/add-abort-signal.js index ba0da5e8bc4ac2..37034e7b5d1cac 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 7fd5df9f27938c..ec9358fc9080d2 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 db407fb251c670..e8659939d6e53d 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -220,7 +220,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);