diff --git a/pgconn/config.go b/pgconn/config.go index 157b8098..942a864a 100644 --- a/pgconn/config.go +++ b/pgconn/config.go @@ -60,10 +60,10 @@ type Config struct { // OnNotification is a callback function called when a notification from the LISTEN/NOTIFY system is received. OnNotification NotificationHandler - // OnPGError is a callback function called when a Postgres error is received by the server. The default handler will close + // OnPgError is a callback function called when a Postgres error is received by the server. The default handler will close // the connection on any FATAL errors. If you override this handler you should call the previously set handler or ensure // that you close on FATAL errors by returning false. - OnPGError ErrorPGHandler + OnPgError PgErrorHandler createdByParseConfig bool // Used to enforce created by ParseConfig rule. } @@ -266,7 +266,7 @@ func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*Con BuildFrontend: func(r io.Reader, w io.Writer) *pgproto3.Frontend { return pgproto3.NewFrontend(r, w) }, - OnPGError: func(_ *PgConn, pgErr *PgError) bool { + OnPgError: func(_ *PgConn, pgErr *PgError) bool { // we want to automatically close any fatal errors if strings.EqualFold(pgErr.Severity, "FATAL") { return false diff --git a/pgconn/pgconn.go b/pgconn/pgconn.go index 71d8e50e..6aebc06b 100644 --- a/pgconn/pgconn.go +++ b/pgconn/pgconn.go @@ -52,11 +52,11 @@ type LookupFunc func(ctx context.Context, host string) (addrs []string, err erro // BuildFrontendFunc is a function that can be used to create Frontend implementation for connection. type BuildFrontendFunc func(r io.Reader, w io.Writer) *pgproto3.Frontend -// ErrorPGHandler is a function that handles errors returned from Postgres. This function must return true to keep +// PgErrorHandler is a function that handles errors returned from Postgres. This function must return true to keep // the connection open. Returning false will cause the connection to be closed immediately. You should return // false on any FATAL-severity errors. This will not receive network errors. The *PgConn is provided so the handler is // aware of the origin of the error, but it must not invoke any query method. -type ErrorPGHandler func(*PgConn, *PgError) bool +type PgErrorHandler func(*PgConn, *PgError) bool // NoticeHandler is a function that can handle notices received from the PostgreSQL server. Notices can be received at // any time, usually during handling of a query response. The *PgConn is provided so the handler is aware of the origin @@ -554,7 +554,7 @@ func (pgConn *PgConn) receiveMessage() (pgproto3.BackendMessage, error) { pgConn.parameterStatuses[msg.Name] = msg.Value case *pgproto3.ErrorResponse: err := ErrorResponseToPgError(msg) - if pgConn.config.OnPGError != nil && !pgConn.config.OnPGError(pgConn, err) { + if pgConn.config.OnPgError != nil && !pgConn.config.OnPgError(pgConn, err) { pgConn.status = connStatusClosed pgConn.conn.Close() // Ignore error as the connection is already broken and there is already an error to return. close(pgConn.cleanupDone) diff --git a/pgconn/pgconn_test.go b/pgconn/pgconn_test.go index c1d9ae18..7ca3992e 100644 --- a/pgconn/pgconn_test.go +++ b/pgconn/pgconn_test.go @@ -3148,7 +3148,7 @@ func TestPipelineCloseDetectsUnsyncedRequests(t *testing.T) { require.EqualError(t, err, "pipeline has unsynced requests") } -func TestConnOnPGError(t *testing.T) { +func TestConnOnPgError(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) @@ -3156,7 +3156,7 @@ func TestConnOnPGError(t *testing.T) { config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE")) require.NoError(t, err) - config.OnPGError = func(c *pgconn.PgConn, pgErr *pgconn.PgError) bool { + config.OnPgError = func(c *pgconn.PgConn, pgErr *pgconn.PgError) bool { require.NotNil(t, c) require.NotNil(t, pgErr) // close connection on undefined tables only