From 868451b090e407094d01eaa953ee8b4fde69ac5c Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Thu, 22 Aug 2024 20:58:47 +0200 Subject: [PATCH] Fix onError callback error handling semantic 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. --- core/shared/src/main/scala/cats/effect/IO.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/shared/src/main/scala/cats/effect/IO.scala b/core/shared/src/main/scala/cats/effect/IO.scala index c2a84bfa1c..4d1f39c86c 100644 --- a/core/shared/src/main/scala/cats/effect/IO.scala +++ b/core/shared/src/main/scala/cats/effect/IO.scala @@ -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) } @@ -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`