Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch exceptions in IOCont #3670

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/shared/src/main/scala/cats/effect/IOFiber.scala
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,15 @@ private final class IOFiber[A](

val get: IO[Any] = IOCont.Get(state)

val next = body[IO].apply(cb, get, FunctionK.id)
val next =
try {
body[IO].apply(cb, get, FunctionK.id)
} catch {
case t if NonFatal(t) =>
IO.raiseError(t)
case t: Throwable =>
onFatalFailure(t)
}

runLoop(next, nextCancelation, nextAutoCede)

Expand Down
8 changes: 8 additions & 0 deletions tests/shared/src/test/scala/cats/effect/IOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,14 @@ class IOSpec extends BaseSpec with Discipline with IOPlatformSpecification {
IO.uncancelable[Unit](_ => throw new RuntimeException)
.handleErrorWith(_ => IO.canceled *> IO.never) must selfCancel
}

"catch exceptions in cont" in ticked { implicit ticker =>
IO.cont[Unit, Unit](new Cont[IO, Unit, Unit] {
override def apply[F[_]](implicit F: MonadCancel[F, Throwable]) = { (_, _, _) =>
throw new Exception
}
}).voidError must completeAs(())
}
}

"finalization" should {
Expand Down