sqlclosecheck
sqlclosecheck copied to clipboard
False positive: db.Queryx
Version: v0.5.1
Repro steps:
package bug_test
import (
"log"
"github.com/jmoiron/sqlx"
)
func Example() {
db, err := sqlx.Open("pgx", "postgres://localhost/db")
if err != nil {
log.Print(err)
return
}
defer db.Close()
rows, err := db.Queryx("SELECT * FROM users")
if err != nil {
log.Print(err)
return
}
defer rows.Close()
}
Result (from golangci-lint
):
example_test.go:17:24: Rows/Stmt/NamedStmt was not closed (sqlclosecheck)
rows, err := db.Queryx("SELECT * FROM users")
➕1
we're facing the same issue in our workflows
Thank you for the report. I will take a look at this over the next few days.
How's it looking with this one? 🙏🏽
+1 in my project following code worked as a solution:
rows, err := db.Queryx("SELECT * FROM users")
if err != nil {
log.Print(err)
return
}
defer func() {
_ = rows.Close()
}()
also worth mentioning: when I used sql instead of sqlx, there was no error
Hi @ryanrolds ! Is there any progress on this issue?