Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgconn: add OnError to Config for error handling #1826

Merged
merged 1 commit into from
Dec 16, 2023

Conversation

jameshartig
Copy link
Contributor

OnError is called on every error response received from Postgres and can be used to close connections on specific errors. Defaults to closing on FATAL-severity errors.

Fixes #1803

@jackc
Copy link
Owner

jackc commented Dec 9, 2023

LGTM with one possible change. Perhaps it could be made more explicit that this is only for PostgreSQL protocol level errors and not for network or any other kind of errors. Maybe more docs on the OnError field or maybe to include PG in the new identifiers (OnPGError, PGErrorHandler, etc.)

OnPGError is called on every error response received from Postgres and can
be used to close connections on specific errors. Defaults to closing on
FATAL-severity errors.

Fixes jackc#1803
@jameshartig
Copy link
Contributor Author

@jackc good point, I just updated that to clarify and added PG to the fields/types.

@jackc jackc merged commit b1631e8 into jackc:master Dec 16, 2023
14 checks passed
@jackc
Copy link
Owner

jackc commented Dec 16, 2023

I merged it. I ended up tweaking the names a bit in df3c5f4 to use Pg instead of PG. I had forgotten that the error type is actually PgError not PGError and figured it is better to be consistent.

@jameshartig
Copy link
Contributor Author

I merged it. I ended up tweaking the names a bit in df3c5f4 to use Pg instead of PG. I had forgotten that the error type is actually PgError not PGError and figured it is better to be consistent.

Good call! Apologies I should've noticed that.

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.

Destroy connection on particular errors
2 participants