Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4039327

Browse files
authored
chore: check version.Err() after version.Next() in ConnectToPostgres (#18437)
1 parent7849794 commit4039327

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
returnnil,xerrors.Errorf("get postgres version: %w",err)
23612361
}
23622362
deferversion.Close()
2363-
ifversion.Err()!=nil {
2364-
returnnil,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+
iferr=version.Err();err!=nil {
2367+
returnnil,xerrors.Errorf("no rows returned for version select: %w",err)
2368+
}
23672369
returnnil,xerrors.Errorf("no rows returned for version select")
23682370
}
23692371
varversionNumint

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp