stream: pre-aborted pipeTo now applies dest failure handling · nodejs/node@037c07a · GitHub
Skip to content

Commit 037c07a

Browse files
jasnelladuh95
authored andcommitted
stream: pre-aborted pipeTo now applies dest failure handling
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode PR-URL: #65658 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 7308492 commit 037c07a

3 files changed

Lines changed: 62 additions & 6 deletions

File tree

‎doc/api/stream_iter.md‎

Lines changed: 2 additions & 1 deletion

‎lib/internal/streams/iter/pull.js‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,18 @@ async function pipeTo(source, ...args) {
10541054

10551055
const signal = options?.signal;
10561056

1057-
// Check for abort
1058-
signal?.throwIfAborted();
1057+
function failWriter(error) {
1058+
if (!options?.preventFail) {
1059+
writer.fail?.(wrapError(error));
1060+
}
1061+
}
1062+
1063+
try {
1064+
signal?.throwIfAborted();
1065+
} catch (error) {
1066+
failWriter(error);
1067+
throw error;
1068+
}
10591069

10601070
const hasWriteSync = typeof writer.writeSync === 'function';
10611071
const useSyncIterableFastPath =
@@ -1192,9 +1202,7 @@ async function pipeTo(source, ...args) {
11921202
}
11931203
}
11941204
} catch (error) {
1195-
if (!options?.preventFail) {
1196-
writer.fail?.(wrapError(error));
1197-
}
1205+
failWriter(error);
11981206
throw error;
11991207
}
12001208

‎test/parallel/test-stream-iter-pipeto-signal.js‎

Lines changed: 47 additions & 0 deletions

0 commit comments

Comments
 (0)