Skip to content

Error type of a transaction seems too generic. #3247

@GijsbertvanVliet

Description

@GijsbertvanVliet

Hi,
Generally for a query in zio quill, which returns some result of type A, if I run this query it would usually return an IO[SQLException, A].
However if I wrap runing of multiple queries in a transaction, then the resulting ZIO always has error type Throwable.

This seems to go against the in code documentation, stating that:

{{{
  val a = run(query[Person].insert(Person(...)): ZIO[DataSource, SQLException, Long]
  val b = run(query[Person]): ZIO[DataSource, SQLException, Person]
  transaction(a *> b): ZIO[DataSource, SQLException, Person]
}}}

So preferably the transaction method would have a signature like:

def transaction[R, E <: Throwable, A](op: ZIO[R, E, A]): ZIO[R, E, A]

However, I see that the dsDelegate.transaction method also depends on a connection, which has error type SQLException.
So since union types are not neatly implemented in scala 2 I understand why a more specific error type then Throwable would be a problem.

I was wondering, doesn't a transaction always expect runned database queries? So the method type be refined to the following?

def transaction[R, E <: SQLException, A](op: ZIO[R, E, A]): ZIO[R, SQLException, A]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions