docs: describe handling PostgreSQL database errors - #2547
Open
superphosphate wants to merge 5 commits into
Open
superphosphate wants to merge 5 commits into
superphosphate wants to merge 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
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.Errorinspection viaerrors.As. - Documents
DatabaseCodeas the PostgreSQL SQLSTATE and points tosqldb.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.
|
|
||
| ## 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`: |
Author
There was a problem hiding this comment.
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" | ||
| ) |
Author
There was a problem hiding this comment.
Addressed in 557b1b6: added "encore.dev/beta/errs" to the import block so the snippet compiles as written.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Documents the existing Go
sqldb.ErrorAPI for handling PostgreSQL errors:sqlerr.Codewitherrors.AsDatabaseCodecontains the PostgreSQL SQLSTATEsqldb.ErrCodefor code-only checksThis documents the capability requested in #386, which is already available in the runtime.
Validation
runtimes/go/storage/sqldb/errors.goandsqlerr/sqlerr.go.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.