typelevel-scalafix icon indicating copy to clipboard operation
typelevel-scalafix copied to clipboard

Add a ` TypelevelMTLSubmarine` rule

Open iRevive opened this issue 2 months ago • 0 comments

https://typelevel.org/blog/2025/09/02/custom-error-types.html

Since we catch this error at the boundary, this whole process is entirely invisible to you unless you write something like handleErrorWith and catch all Throwable-typed errors within the scope, in which case you might see something of type Submarine. The correct thing to do with this error type, should you see it, depends considerably on exactly why you’re writing handleErrorWith, and as it turns out this is exactly the whole point!

It's relatively easy to run into problems when you call standard error-handling on an expression that requires Raise. The new rule forbids using error-handling options. For example:

def raiseError: Raise[IO, String] ?=> IO[Unit] = r =>
  r.raise("boom")

def standardError: IO[Unit] =
  IO.raiseError(new RuntimeException("boom"))

Handle.allow[String] {
  for {
    _ <- raiseError.onError(e => IO.println("Error: " + e)) // forbidden
    _ <- standardError.onError(e => IO.println("Error: " + e)) // allowed
  } yield 
}

iRevive avatar Oct 24 '25 14:10 iRevive