Skip to content

Commit b6a032f

Browse files
authored
ensure Channel executor catches defects in doneHalt (#4430)
1 parent 2473ad5 commit b6a032f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

.changeset/neat-ducks-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
ensure Channel executor catches defects in doneHalt

packages/effect/src/internal/channel.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,9 +1855,15 @@ export const orDieWith = dual<
18551855
self: Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>,
18561856
f: (e: OutErr) => unknown
18571857
): Channel.Channel<OutElem, InElem, never, InErr, OutDone, InDone, Env> =>
1858-
catchAll(self, (e) => {
1859-
throw f(e)
1860-
}) as Channel.Channel<OutElem, InElem, never, InErr, OutDone, InDone, Env>)
1858+
catchAll(self, (e) => core.failCauseSync(() => Cause.die(f(e)))) as Channel.Channel<
1859+
OutElem,
1860+
InElem,
1861+
never,
1862+
InErr,
1863+
OutDone,
1864+
InDone,
1865+
Env
1866+
>)
18611867

18621868
/** @internal */
18631869
export const orElse = dual<

packages/effect/src/internal/channel/channelExecutor.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,11 @@ export class ChannelExecutor<
503503
const head = this._doneStack[this._doneStack.length - 1] as Continuation.Primitive
504504
if (head._tag === ContinuationOpCodes.OP_CONTINUATION_K) {
505505
this._doneStack.pop()
506-
this._currentChannel = head.onHalt(cause) as core.Primitive
506+
try {
507+
this._currentChannel = head.onHalt(cause) as core.Primitive
508+
} catch (error) {
509+
this._currentChannel = core.failCause(Cause.die(error)) as core.Primitive
510+
}
507511
return undefined
508512
}
509513

0 commit comments

Comments
 (0)