mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
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:
4 files changed
+8
-7
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user