Skip to content

Commit 046deba

Browse files
jasnelltargos
authored andcommitted
stream: use cause options in AbortError constructors
Signed-off-by: James M Snell <[email protected]> PR-URL: #41008 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 2aae868 commit 046deba

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lib/internal/streams/add-abort-signal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports.addAbortSignalNoValidate = function(signal, stream) {
3434
return stream;
3535
}
3636
const onAbort = () => {
37-
stream.destroy(new AbortError());
37+
stream.destroy(new AbortError(undefined, { cause: signal.reason }));
3838
};
3939
if (signal.aborted) {
4040
onAbort();

lib/internal/streams/duplexify.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ function fromAsyncGen(fn) {
214214
const { chunk, done, cb } = await _promise;
215215
process.nextTick(cb);
216216
if (done) return;
217-
if (signal.aborted) throw new AbortError();
217+
if (signal.aborted)
218+
throw new AbortError(undefined, { cause: signal.reason });
218219
({ promise, resolve } = createDeferredPromise());
219220
yield chunk;
220221
}

lib/internal/streams/end-of-stream.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ function eos(stream, options, callback) {
220220
// Keep it because cleanup removes it.
221221
const endCallback = callback;
222222
cleanup();
223-
endCallback.call(stream, new AbortError());
223+
endCallback.call(
224+
stream,
225+
new AbortError(undefined, { cause: options.signal.reason }));
224226
};
225227
if (options.signal.aborted) {
226228
process.nextTick(abort);

0 commit comments

Comments
 (0)