zio-quill icon indicating copy to clipboard operation
zio-quill copied to clipboard

Creating a transaction in zio-jdbc-postgres drops the error type

Open sloane opened this issue 4 years ago • 2 comments

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

sloane avatar Jul 22 '21 21:07 sloane

Wow, just came here to open this same issue. You beat me by 8 hours!

virusdave avatar Jul 23 '21 05:07 virusdave

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.

renanrfranca avatar Mar 11 '22 16:03 renanrfranca

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 🙂

guizmaii avatar Oct 19 '23 12:10 guizmaii