typelevel / typelevel/skunk

recoverWith bugs

Open
#523 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.