FORGE-85: classifyDbError() for Postgres and SQLite constraint errors #706
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
gmackie/ForgeGraph!706
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "FORGE-85-db-errors"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part 4 of FORGE-85 (D1 Phase 2, parent FORGE-69). Stacked on #703.
packages/db/src/errors.ts:classifyDbError(err)→{ kind: "unique" | "foreign_key", dialect, constraint?, columns? }. Postgres: SQLSTATE 23505/23503 withconstraint_name(postgres-js) orconstraint(pg). SQLite/D1: "UNIQUE constraint failed: t.a, t.b" (columns), "UNIQUE constraint failed: index 'name'" (expression indexes), "FOREIGN KEY constraint failed" (no name), including D1'sD1_ERROR: …: SQLITE_CONSTRAINTwrapper. Walks drizzle'sDrizzleQueryError.causechain. HelpersisUniqueViolation(err, constraint?),isForeignKeyViolation(err).Behaviour note: gcp.ts, cron-eval.ts and the rollback route checked only the top-level
err.code. drizzle 1.0 throwsDrizzleQueryErrorwith the driver error on.cause, so those three never matched a wrapped violation; they now do (existing binding returned / window skipped / 409 instead of a 500). auto-dispatch and targets already walkedcauseand are unchanged.Verification
packages/db/src/errors.test.ts(8): realnode:sqliteerrors (column, expression index, FK), D1 messages, postgres-js / node-postgres shapes, DrizzleQueryError wrapping, cause loops.packages/api/src/__tests__/db-error-classification.database.test.ts: real drizzle errors from Postgres 16 (unique with constraint name; FK). The FK case is skipped on local PGlite, which doesn't enforce FKs; CI runs real Postgres.🤖 Generated with Claude Code
ee16d942ec71aba48e0b71aba48e0b8453fef3778453fef3772a2c04da40