recoverWith bugs
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.7k
- Forks
- 175
- Avg merge
- 5d 14h
- Merged PRs (30d)
- 9
Description
Hi, I would like to report two bugs as follows.
When I execute an insert statement without transaction as follows, for some reason, the SqlState.ForeignKeyViolation cannot be caught/recovered from.
sessionPool.use { session =>
session.prepare(...).use { cmd =>
cmd
.execute(a)
.void
.recoverWith {
case e @ SqlState.ForeignKeyViolation(_) if e.getMessage.contains("FK_some_foreign_key") =>
Exception.SomeForeignKeyNotFound(a.someForeignKey).raise[F, Unit]
}
... (omitted)
I had to use a transaction in order for the recoverWith to work.
(for {
session <- sessionPool
command <- session.prepare(...)
_ <- session.transaction
} yield command)
.use { cmd =>
cmd.execute(a).void
}
.recoverWith {
case e @ SqlState.ForeignKeyViolation(_) if e.getMessage.contains("FK_some_foreign_key") =>
Exception.SomeForeignKeyNotFound(a.someForeignKey).raise[F, Unit]
}
... (omitted)
Another bug (which might be related) is if I recover from a SqlState.UniqueViolation this way, the full trace/error message still gets printed in stdout (while it should not).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Scala examples using sessionPool, recoverWith, and a PostgreSQL foreign-key violation, both with and without a transaction. Then reproduce recovery from SqlState.UniqueViolation and observe stdout; done means both errors can be recovered as shown without an unexpected trace being printed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgres, scala
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100