Are there any strategies for raising an error thro...
# arrow
k
Are there any strategies for raising an error through a lambda, something like raising through the transaction block of sqldelight?
Copy code
suspend fun persist(foo: String): Either<Error, Unit> = either {
        // Raise context may escape through this lambda
        database.transaction {
            val id = repository.insertFoo(foo).bind()
            if (id == 0) {
                rollback()
                raise(Error("Failed to insert foo"))
            }
        }
    }
a
this depends a lot on what
transaction
actually does. If the transaction is run in place, then doing what you do is fine otherwise, another option is to hook at some kind of callback (which I don't know if they exist in SQLDelight). Something along the lines of:
Copy code
database.transaction {
  val id = repository.insertFoo(foo).bind()
  if (id == 0) rollback()
}.onRollback { raise(...) }
k
Thanks, the former is what I wanted to achieve however i got concerned with the linter raising a warning that raise may escape. Thanks @Alejandro Serrano.Mena
a
the linter is a best-effort we've built; if you feel like we should take the case of
transaction
better into account, feel free to open an issue and we can explore it
👍 1