Skip to content

Commit

Permalink
Fix onError callback error handling semantic
Browse files Browse the repository at this point in the history
For the ApplicativeError.onError method, We let the callback's
error propagate to match with cats's ApplicativeError semantic.
For the old onError, We report callback's error and raise the
original error instead.
  • Loading branch information
lenguyenthanh committed Aug 22, 2024
1 parent 4764d05 commit 868451b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {

@deprecated("Use onError with PartialFunction argument", "3.6.0")
def onError(f: Throwable => IO[Unit]): IO[A] = {
val pf: PartialFunction[Throwable, IO[Unit]] = { case t => f(t) }
val pf: PartialFunction[Throwable, IO[Unit]] = { case t => f(t).reportError }
onError(pf)
}

Expand All @@ -596,8 +596,7 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
* Implements `ApplicativeError.onError`.
*/
def onError(pf: PartialFunction[Throwable, IO[Unit]]): IO[A] =
handleErrorWith(t =>
pf.applyOrElse(t, (_: Throwable) => IO.unit).reportError *> IO.raiseError(t))
handleErrorWith(t => pf.applyOrElse(t, (_: Throwable) => IO.unit) *> IO.raiseError(t))

/**
* Like `Parallel.parProductL`
Expand Down

0 comments on commit 868451b

Please sign in to comment.