I have recently discovered a strange behaviour while trying to use .timeout on the Resource of the Client.run(_) from http4s. As I later investigated, the issue has nothing to do with http4s, ember or fs2.
//> using scala 3
//> using dep org.typelevel::cats-effect:3.7.1
import cats.effect.*
import cats.effect.syntax.temporal.*
import scala.concurrent.duration.*
object ReproMakeBug extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
Resource
.make(IO.raiseError[Unit](new RuntimeException("boom")))(_ => IO.unit)
.timeout(300.millis)
.use(_ => IO.unit)
.handleErrorWith { e =>
IO.println(s"[handled] ${e.getClass.getName}: ${e.getMessage}")
}
.as(ExitCode.Success)
}
This code produces two error mesages: one defined in the code and one by IOApp.reportFailure. For me this is strange, because the error is handled and I expect that reportFailure should not be called.
Code with eval doesn't produce such message:
//> using scala 3
//> using dep org.typelevel::cats-effect:3.7.1
import cats.effect.*
import cats.effect.syntax.temporal.*
import scala.concurrent.duration.*
object ReproEvalControl extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
Resource
.eval(IO.raiseError[Unit](new RuntimeException("boom")))
.timeout(300.millis)
.use(_ => IO.unit)
.handleErrorWith { e =>
IO.println(s"[handled] ${e.getClass.getName}: ${e.getMessage}")
}
.guarantee(IO.sleep(600.millis))
.as(ExitCode.Success)
}
I have recently discovered a strange behaviour while trying to use
.timeouton theResourceof theClient.run(_)from http4s. As I later investigated, the issue has nothing to do with http4s, ember or fs2.This code produces two error mesages: one defined in the code and one by
IOApp.reportFailure. For me this is strange, because the error is handled and I expect thatreportFailureshould not be called.Code with eval doesn't produce such message: