From 5982e4b4f881f4a71c4cacb8f2addf3ac5386921 Mon Sep 17 00:00:00 2001 From: Matthew Gabeler-Lee Date: Mon, 4 Apr 2022 15:27:52 -0400 Subject: [PATCH] fix detection of database does not exist error during connect --- pgconn.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pgconn.go b/pgconn.go index 29889a7..9a496ed 100644 --- a/pgconn.go +++ b/pgconn.go @@ -154,9 +154,12 @@ func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err err break } else if pgerr, ok := err.(*PgError); ok { err = &connectError{config: config, msg: "server error", err: pgerr} - ERRCODE_INVALID_PASSWORD := "28P01" // wrong password - ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION := "28000" // db does not exist - if pgerr.Code == ERRCODE_INVALID_PASSWORD || pgerr.Code == ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION { + const ERRCODE_INVALID_PASSWORD = "28P01" // wrong password + const ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION = "28000" // wrong password or bad pg_hba.conf settings + const ERRCODE_INVALID_CATALOG_NAME = "3D000" // db does not exist + if pgerr.Code == ERRCODE_INVALID_PASSWORD || + pgerr.Code == ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION || + pgerr.Code == ERRCODE_INVALID_CATALOG_NAME { break } }