Skip to content

Commit

Permalink
fix detection of database does not exist error during connect
Browse files Browse the repository at this point in the history
  • Loading branch information
mgabeler-lee-6rs authored and jackc committed Apr 9, 2022
1 parent b7a85d1 commit 5982e4b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pgconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 5982e4b

Please sign in to comment.