Skip to content

docs: describe handling PostgreSQL database errors - #2547

Open
superphosphate wants to merge 5 commits into
encoredev:mainfrom
superphosphate:docs/sqldb-database-error-codes
Open

superphosphate wants to merge 5 commits into
encoredev:mainfrom
superphosphate:docs/sqldb-database-error-codes

Conversation

@superphosphate

@superphosphate superphosphate commented Aug 21, 2026 •

Copy link
Copy Markdown

Summary

Documents the existing Go sqldb.Error API for handling PostgreSQL errors:

  • shows how to inspect sqlerr.Code with errors.As
  • explains that DatabaseCode contains the PostgreSQL SQLSTATE
  • points readers to sqldb.ErrCode for code-only checks

This documents the capability requested in #386, which is already available in the runtime.

Validation

  • Verified the example against runtimes/go/storage/sqldb/errors.go and sqlerr/sqlerr.go.
  • Confirmed the PR diff contains only the added documentation section.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Copilot AI lite review requested due to automatic review settings August 21, 2026 02:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds documentation describing how to inspect Encore Go sqldb database errors (including PostgreSQL SQLSTATE) so users can reliably detect common PostgreSQL error conditions such as unique constraint violations.

Changes:

  • Adds a new “Database Errors” section explaining *sqldb.Error inspection via errors.As.
  • Documents DatabaseCode as the PostgreSQL SQLSTATE and points to sqldb.ErrCode(err) for code-only checks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/go/primitives/api-errors.md Outdated

## Database Errors

Database operations can return `*sqldb.Error` when PostgreSQL reports an error. Use `errors.As` to inspect the error's general Encore code and PostgreSQL-specific `DatabaseCode`:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 557b1b6: reworded to say errors wrap *sqldb.Error and clarified dbErr.Code is a sqlerr.Code, not an Encore errs.ErrCode.

Comment on lines +118 to +123
import (
"errors"

"encore.dev/storage/sqldb"
"encore.dev/storage/sqldb/sqlerr"
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 557b1b6: added "encore.dev/beta/errs" to the import block so the snippet compiles as written.

This branch has not been deployed

No deployments
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.

2 participants