A ZIO 2 tapError and debug/when example

There’s a good ZIO 2 tapError example at the URL I have linked to, specifically:

import zio._

object MainApp extends ZIOAppDefault {
  val myApp: ZIO[Any, NumberFormatException, Int] =
    Console.readLine
           .mapAttempt(_.toInt)
           .refineToOrDie[NumberFormatException]
           .tapError { e =>
              ZIO.debug(s"user entered an invalid input: ${e}")
                 .when(e.isInstanceOf[NumberFormatException])
           }

  def run = myApp
}

I’m currently working on debugging a ZIO 2 application, and built-in methods like tap, tapError, and debug are very helpful in this process.