Skip to content

Commit

Permalink
ensure Channel executor catches defects in doneHalt (#4430)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Feb 11, 2025
1 parent 2473ad5 commit b6a032f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-ducks-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

ensure Channel executor catches defects in doneHalt
12 changes: 9 additions & 3 deletions packages/effect/src/internal/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1855,9 +1855,15 @@ export const orDieWith = dual<
self: Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>,
f: (e: OutErr) => unknown
): Channel.Channel<OutElem, InElem, never, InErr, OutDone, InDone, Env> =>
catchAll(self, (e) => {
throw f(e)
}) as Channel.Channel<OutElem, InElem, never, InErr, OutDone, InDone, Env>)
catchAll(self, (e) => core.failCauseSync(() => Cause.die(f(e)))) as Channel.Channel<
OutElem,
InElem,
never,
InErr,
OutDone,
InDone,
Env
>)

/** @internal */
export const orElse = dual<
Expand Down
6 changes: 5 additions & 1 deletion packages/effect/src/internal/channel/channelExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,11 @@ export class ChannelExecutor<
const head = this._doneStack[this._doneStack.length - 1] as Continuation.Primitive
if (head._tag === ContinuationOpCodes.OP_CONTINUATION_K) {
this._doneStack.pop()
this._currentChannel = head.onHalt(cause) as core.Primitive
try {
this._currentChannel = head.onHalt(cause) as core.Primitive
} catch (error) {
this._currentChannel = core.failCause(Cause.die(error)) as core.Primitive
}
return undefined
}

Expand Down

0 comments on commit b6a032f

Please sign in to comment.