Skip to content

docs: document DatabaseError and its fields - #3788

Open
u9822914324-web wants to merge 1 commit into
brianc:masterfrom
u9822914324-web:docs/database-error
Open

u9822914324-web wants to merge 1 commit into
brianc:masterfrom
u9822914324-web:docs/database-error

Conversation

@u9822914324-web

Copy link
Copy Markdown

Closes #3770.

Why

The only error-handling guidance in the docs is a short try/catch example on the landing page. It shows that errors happen but not what they contain, so there is no documented way to find out that a failure carries a SQLSTATE code, a constraint, or a detail — which is exactly what you need to handle an expected error like a unique violation.

What

  • Adds docs/pages/apis/errors.mdx (pg.DatabaseError) documenting every field, with an example that branches on err instanceof DatabaseError to separate server-side failures from connection/TLS/timeout failures.
  • Registers it in docs/pages/apis/_meta.js next to pg.Result.
  • Links it from the Error Handling section on the landing page.

Accuracy

Field descriptions and their protocol letters were taken from parseErrorMessage in packages/pg-protocol/src/parser.ts, so they describe what the driver actually populates rather than being transcribed from the PostgreSQL manual. The page calls out two things that are easy to get wrong:

  • every field except message, length, and name is optional and can be undefined, since the server only sends the fields that apply
  • name is 'error', not 'DatabaseError' — it shadows the usual Error.name

Docs-only; no runtime code touched. prettier --check passes on all three files. yarn lint scopes to packages/** and benchmark/**, so it is unaffected.

This was prepared with AI assistance (Claude); the source mapping and field semantics were verified against the parser in this repository.

🤖 Generated with Claude Code

Closes brianc#3770.

The only guidance on error handling was a short try/catch example on the
landing page, which left no way to find out what a server error actually
carries. This adds a pg.DatabaseError API page covering every field, and
links it from that section.

Field descriptions and their protocol letters are taken from
parseErrorMessage in packages/pg-protocol/src/parser.ts, so they match what
the driver actually populates rather than the PostgreSQL docs alone.

The page also spells out two things that are easy to get wrong: every field
except message, length, and name is optional and can be undefined, and name
is 'error' rather than 'DatabaseError' because it shadows Error.name.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please add documentation about DatabaseError

1 participant