Changelog - 2026-11-08
PostgresErrors.find finds the Postgres error inside a wrapped error
New Feature Bug FixIn one line. PostgresErrors.find({ error }) returns the Postgres error hidden in a wrapped error, with its code, constraint and detail, so you no longer write your own cause walker to spot a unique violation.
What changed
- A new helper.
PostgresErrors.find({ error })followscauseand returns anIPostgresError(code, plusconstraint,detail,table,column,schemaandmessagewhen the server sent them), orundefined. ComparecodewithPostgresErrorCodes. - The same fields for every driver. node-postgres, postgres-js and PGlite are read into one shape: postgres-js's
constraint_name,table_name,column_nameandschema_namecome back asconstraint,table,columnandschema. - Safe to call on anything. It never throws. A
causecycle, a getter that throws, a Proxy, or a value that is not an object givesundefined. - Bounded. It follows at most 10
causehops (PostgresErrors.MAX_DEPTH). The outermost error with a real SQLSTATE wins. - A
codecounts only when it is a SQLSTATE. Five characters of digits and upper-case letters.ECONNRESETor a number is skipped and the walk goes on. - The error handler uses it too. It used to read one level of
cause. A unique violation or a deadlock wrapped two or three levels deep now answers 400 or 409 instead of 500, and an outer error with a non-SQLSTATEcodeno longer hides the Postgres error under it.
typescript
import { PostgresErrorCodes, PostgresErrors } from '@venizia/ignis';
const pgError = PostgresErrors.find({ error });
if (pgError?.code === PostgresErrorCodes.UNIQUE_VIOLATION) {
// pgError.constraint, pgError.table, pgError.detail
}Who is affected
- Apps with their own
causewalker for Postgres errors. You can replace it withPostgresErrors.find. No action needed. - Apps whose ORM wraps the driver error more than one level. Those errors now get the 400 or 409 they should have had.
- Everyone else. No action needed.
Details
- In non-production responses,
Detail:,Table:andConstraint:now come from the same error that supplied thecode, not always from the firstcause. Production still returns the base message only.
| File | Package |
|---|---|
src/base/middlewares/app-error/postgres-errors.ts | kernel |
src/base/middlewares/app-error/database.handler.ts | kernel |