Creating a transaction in zio-jdbc-postgres drops the error type
Version: (e.g. 0.4.1-SNAPSHOT)
Module: (e.g. quill-jdbc-postgres)
Database: (e.g. postgres)
Expected behavior
If I have a ZIO[R, E, A] and I create a transaction around it, I should get back a ZIO[R, E, A].
Actual behavior
I get back a ZIO[R, Throwable, A], which is less-precise than what I put into it. There is just a small mistake in the type definition of the function.
def transaction[A](f: ZIO[Has[Connection], Throwable, A]): ZIO[Has[Connection], Throwable, A]
Instead of hard-coding Throwable here, we should add a type E to the list of generics.
Steps to reproduce the behavior
If the issue can be reproduced using a mirror context, please provide a scastie snippet that reproduces it. See https://scastie.scala-lang.org/fwbrasil/Z2CeR2qHQJK6EyQWUBhANA as an example. Remember to select the correct Quill version in the left menu.
Workaround
I am submitting a fix.
@getquill/maintainers
Wow, just came here to open this same issue. You beat me by 8 hours!
I'm a beginner in Zio and even Scala as a whole so I can't figure this out myself, what are the reasons for limiting it to Throwable here? It's a pretty annoying limitation, but I suppose there must be a reason why we need a Throwable.
I don't think we can do better than Throwable as the internals of this function can return a ZIO[R, SQLException, A].
So even if we use E <: Throwable as it was suggested here, Scala will have to find the common type between E and SQLException to compute the return type of this function and the common type will always be Throwable
Closing. Let me know if I'm wrong, I'll re-open if I am 🙂