Skip to content

Commit a00e58b

Browse files
committed
stream: preserve push signal abort reason
Pass the stream-wide signal reason directly to writer.fail() so valid non-Error abort reasons are not replaced with an AbortError. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol
1 parent 6a3d80f commit a00e58b

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/internal/streams/iter/push.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const {
2424
ERR_INVALID_STATE,
2525
},
2626
} = require('internal/errors');
27-
const { isError, lazyDOMException } = require('internal/util');
27+
const { lazyDOMException } = require('internal/util');
2828
const {
2929
validateAbortSignal,
3030
validateInteger,
@@ -105,9 +105,7 @@ class PushQueue {
105105

106106
if (this.#signal) {
107107
this.#abortHandler = () => {
108-
this.fail(isError(this.#signal.reason) ?
109-
this.#signal.reason :
110-
lazyDOMException('Aborted', 'AbortError'));
108+
this.fail(this.#signal.reason);
111109
};
112110
onSignalAbort(this.#signal, this.#abortHandler);
113111
}

test/parallel/test-stream-iter-push-basic.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ async function testAbortSignal() {
107107
);
108108
}
109109

110+
async function testAbortSignalReason() {
111+
const reason = 'test reason';
112+
const ac = new AbortController();
113+
const { writer } = push({ signal: ac.signal });
114+
115+
ac.abort(reason);
116+
117+
await assert.rejects(writer.write('data'), (err) => err === reason);
118+
}
119+
110120
async function testPreAbortedSignal() {
111121
const { readable } = push({ signal: AbortSignal.abort() });
112122
await assert.rejects(async () => {
@@ -172,6 +182,7 @@ Promise.all([
172182
testWriterFail(),
173183
testConsumerBreak(),
174184
testAbortSignal(),
185+
testAbortSignalReason(),
175186
testPreAbortedSignal(),
176187
testConsumerBreakWriteSyncReturnsFalse(),
177188
testPushWithTransforms(),

0 commit comments

Comments
 (0)