stream: use cause options in AbortError constructors

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/41008
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
James M Snell authored and Michaël Zasso committed 2022-08-01 16:48:36 +02:00
1 parent 2aae868fa2
commit 046debaee0
3 files changed
+6 -3

No files matched your search

+1 -1
View File
@@ -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();
+2 -1
View File
@@ -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;
}
+3 -1
View File
@@ -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);