zio-optics
zio-optics copied to clipboard
OpticFailure error message gets discarded
when:
val tmap: TMap[String, String] = ???
val effect = tmap.key("key does not exist").get(()).commit // does not preserve error message (if error channel type is Throwable)
expect stacktrace message starting with:
zio.optics.OpticFailureModule$OpticFailure: zio.stm.TMap@34449d84 did not satify hasKey(key does not exist)
but was:
zio.optics.OpticFailureModule$OpticFailure
full example:
import zio.stm._
import zio.optics.toptics._
object TestMain extends zio.App {
override def run(args: List[String]): URIO[ZEnv,ExitCode] = {
val stm = for {
map <- TMap.empty[String, String]
notFound <- map.key("key does not exist").get(())
} yield notFound
val effect: ZIO[Any,Throwable,String] = stm.commit
val effectWithErrorMessage: ZIO[Any,Throwable,String] = stm.mapError(e => new RuntimeException(s"error message was ${e.message}")).commit
effect.catchAll(e => ZIO.effect(e.printStackTrace())).exitCode
//effectWithErrorMessage.catchAll(e => ZIO.effect(e.printStackTrace())).exitCode
}
}