Navigation Menu

Skip to content

Commit

Permalink
stream: use cause options in AbortError constructors
Browse files Browse the repository at this point in the history
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #41008
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
jasnell authored and danielleadams committed Dec 13, 2021
1 parent 67124ac commit 01e8c15
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/internal/streams/add-abort-signal.js
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/streams/duplexify.js
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/streams/end-of-stream.js
Expand Up @@ -215,7 +215,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);
Expand Down
6 changes: 2 additions & 4 deletions lib/internal/webstreams/adapters.js
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 01e8c15

Please sign in to comment.