Expand description
Translating PostgreSQL failures into the closed error surface of the persistence contract.
A store speaks StoreError and nothing else, so the runtime can classify a
persistence failure without knowing which database is underneath. The
translation below is the whole of that promise for this adapter, and the
distinction that matters most is between nothing was written and the write
may have landed:
| PostgreSQL failure | StoreError | Why |
|---|---|---|
| unique or exclusion violation | Conflict | a uniqueness rule refused the row; nothing was written |
| foreign key violation | Conflict | a referenced row was missing or in use; nothing was written |
| check violation | Other(INVALID_RECORD) | the row itself is illegal, e.g. a negative revision |
| serialization failure, deadlock | Conflict | the transaction lost a race and rolled back whole |
statement_timeout cancellation | Timeout | the statement was cut off mid-flight |
| connection exception, too many connections | Unavailable | the statement never ran |
| any other SQLSTATE | Other("turnframe.store.postgres.<sqlstate>") | a stable, loggable code |
| a value that will not decode | Corrupt | stored data disagrees with the schema this adapter relies on |
Every write this adapter makes runs inside a transaction, so a connection
that dies mid-statement rolls the transaction back and nothing survives —
which is why a transport error maps to Unavailable rather than Timeout.
The single exception is the COMMIT itself: a failure there is genuinely
indeterminate, and commit_failed maps it to Timeout so the caller
re-reads instead of retrying (spec §16.5).
No message from the database is ever carried into a StoreError: a
constraint name or a server message can quote the row that failed, and rows
hold user data. Only SQLSTATE codes cross the boundary.
Constants§
- POSTGRES_
CODE_ PREFIX - Prefix of the stable codes this adapter reports for an unclassified PostgreSQL error, completed by the five-character SQLSTATE.
Functions§
- commit_
failed - Maps the failure of a
COMMITstatement. - store_
error - Maps a
sqlxfailure onto the contract’s error surface.