Use "Pg" instead of "PG" in new PgError related identifiers

Arguably, PGError might have been better. But since the precedent is
long since established it is better to be consistent.
pull/1837/head
Jack Christensen 2023-12-15 18:33:51 -06:00
parent b1631e8e35
commit df3c5f4df8
3 changed files with 8 additions and 8 deletions

View File

@ -60,10 +60,10 @@ type Config struct {
// OnNotification is a callback function called when a notification from the LISTEN/NOTIFY system is received. // OnNotification is a callback function called when a notification from the LISTEN/NOTIFY system is received.
OnNotification NotificationHandler 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 // 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. // that you close on FATAL errors by returning false.
OnPGError ErrorPGHandler OnPgError PgErrorHandler
createdByParseConfig bool // Used to enforce created by ParseConfig rule. 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 { BuildFrontend: func(r io.Reader, w io.Writer) *pgproto3.Frontend {
return pgproto3.NewFrontend(r, w) 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 // we want to automatically close any fatal errors
if strings.EqualFold(pgErr.Severity, "FATAL") { if strings.EqualFold(pgErr.Severity, "FATAL") {
return false return false

View File

@ -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. // 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 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 // 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 // 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. // 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 // 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 // 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 pgConn.parameterStatuses[msg.Name] = msg.Value
case *pgproto3.ErrorResponse: case *pgproto3.ErrorResponse:
err := ErrorResponseToPgError(msg) 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.status = connStatusClosed
pgConn.conn.Close() // Ignore error as the connection is already broken and there is already an error to return. pgConn.conn.Close() // Ignore error as the connection is already broken and there is already an error to return.
close(pgConn.cleanupDone) close(pgConn.cleanupDone)

View File

@ -3148,7 +3148,7 @@ func TestPipelineCloseDetectsUnsyncedRequests(t *testing.T) {
require.EqualError(t, err, "pipeline has unsynced requests") require.EqualError(t, err, "pipeline has unsynced requests")
} }
func TestConnOnPGError(t *testing.T) { func TestConnOnPgError(t *testing.T) {
t.Parallel() t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) 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")) config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
require.NoError(t, err) 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, c)
require.NotNil(t, pgErr) require.NotNil(t, pgErr)
// close connection on undefined tables only // close connection on undefined tables only