Skip to main content

Module error

Module error 

Source
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 failureStoreErrorWhy
unique or exclusion violationConflicta uniqueness rule refused the row; nothing was written
foreign key violationConflicta referenced row was missing or in use; nothing was written
check violationOther(INVALID_RECORD)the row itself is illegal, e.g. a negative revision
serialization failure, deadlockConflictthe transaction lost a race and rolled back whole
statement_timeout cancellationTimeoutthe statement was cut off mid-flight
connection exception, too many connectionsUnavailablethe statement never ran
any other SQLSTATEOther("turnframe.store.postgres.<sqlstate>")a stable, loggable code
a value that will not decodeCorruptstored 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 COMMIT statement.
store_error
Maps a sqlx failure onto the contract’s error surface.