Skip to content

Commit 01e8c15

Browse files
jasnelldanielleadams
authored andcommittedDec 13, 2021
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 67124ac commit 01e8c15

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
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
@@ -215,7 +215,9 @@ function eos(stream, options, callback) {
215215
// Keep it because cleanup removes it.
216216
const endCallback = callback;
217217
cleanup();
218-
endCallback.call(stream, new AbortError());
218+
endCallback.call(
219+
stream,
220+
new AbortError(undefined, { cause: options.signal.reason }));
219221
};
220222
if (options.signal.aborted) {
221223
process.nextTick(abort);

‎lib/internal/webstreams/adapters.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ function newWritableStreamFromStreamWritable(streamWritable) {
122122

123123
const cleanup = finished(streamWritable, (error) => {
124124
if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
125-
const err = new AbortError();
126-
err.cause = error;
125+
const err = new AbortError(undefined, { cause: error });
127126
error = err;
128127
}
129128

@@ -403,8 +402,7 @@ function newReadableStreamFromStreamReadable(streamReadable) {
403402

404403
const cleanup = finished(streamReadable, (error) => {
405404
if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
406-
const err = new AbortError();
407-
err.cause = error;
405+
const err = new AbortError(undefined, { cause: error });
408406
error = err;
409407
}
410408

0 commit comments

Comments
 (0)
Please sign in to comment.