Behaviour of `MonadCancelThrow[EitherT[IO, Throwable, *]]`
Open
@armanbilge is already working on this.
Since Jun 12, 2022.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
This issue sounds somewhat familiar, and apologies if I forgot the exact discussion, however I stumbled on it in the wild in the context of https://github.com/typelevel/fs2/pull/2895 and found it pretty confusing.
In particular:
- the behaviour of
MonadThrowandMonadCancelThrowis inconsistent - the behaviour of
MonadCancelThrowis weird: excluding cancelation, if something short circuits aflatMapI expect to be able tohandleErrorit. Ofc this expectation is broken when you have two error channels, but MonadThrow works around it
val a: EitherT[IO, Throwable, Unit] =
EitherT.leftT[IO, Unit](new Exception("Yooo"))
val console = Console[EitherT[IO, Throwable, *]]
def foo(fa: EitherT[IO, Throwable, Unit]): EitherT[IO, Throwable, Unit] =
fa.flatMap(_ => console.println("not printed"))
.handleError(_ => ())
def bar[F[_]: MonadThrow: Console](fa: F[Unit]): F[Unit] =
fa.flatMap(_ => Console[F].println("not printed"))
.handleError(_ => ())
def baz[F[_]: MonadCancelThrow: Console](fa: F[Unit]): F[Unit] =
fa.flatMap(_ => Console[F].println("not printed"))
.handleError(_ => ())
def x = foo(a).value.unsafeRunSync()
def y = bar(a).value.unsafeRunSync()
def z = baz(a).value.unsafeRunSync()
scala> x
val res0: Either[Throwable,Unit] = Right(())
scala> y
val res1: Either[Throwable,Unit] = Right(())
scala> z
val res2: Either[Throwable,Unit] = Left(java.lang.Exception: Yooo)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.