Skip to content

Commit 4039327

Browse files
authored
chore: check version.Err() after version.Next() in ConnectToPostgres (#18437)
1 parent 7849794 commit 4039327

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cli/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,10 +2360,12 @@ func ConnectToPostgres(ctx context.Context, logger slog.Logger, driver string, d
23602360
return nil, xerrors.Errorf("get postgres version: %w", err)
23612361
}
23622362
defer version.Close()
2363-
if version.Err() != nil {
2364-
return nil, xerrors.Errorf("version select: %w", version.Err())
2365-
}
23662363
if !version.Next() {
2364+
// it's critical we assign to the err variable, otherwise the defer statement
2365+
// that runs db.Close() will not execute it
2366+
if err = version.Err(); err != nil {
2367+
return nil, xerrors.Errorf("no rows returned for version select: %w", err)
2368+
}
23672369
return nil, xerrors.Errorf("no rows returned for version select")
23682370
}
23692371
var versionNum int

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy