Skip to content

Commit 8e1b13f

Browse files
jingyugaojingyugao
jingyugao
authored andcommitted
fix rowserrcheck reports false positive #943
1 parent 89367ae commit 8e1b13f

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/esimonov/ifshort v1.0.0
1515
github.com/fatih/color v1.10.0
1616
github.com/go-critic/go-critic v0.5.3
17+
github.com/go-sql-driver/mysql v1.4.0
1718
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
1819
github.com/gofrs/flock v0.8.0
1920
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
@@ -30,8 +31,9 @@ require (
3031
github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0
3132
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
3233
github.com/jgautheron/goconst v0.0.0-20201117150253-ccae5bf973f3
33-
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a
34+
github.com/jingyugao/rowserrcheck v0.0.0-20210130005344-c6a0c12dd98d
3435
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
36+
github.com/jmoiron/sqlx v1.2.0
3537
github.com/kulti/thelper v0.2.1
3638
github.com/kunwardeep/paralleltest v1.0.2
3739
github.com/kyoh86/exportloopref v0.1.8
@@ -69,6 +71,7 @@ require (
6971
github.com/ultraware/whitespace v0.0.4
7072
github.com/uudashr/gocognit v1.0.1
7173
github.com/valyala/quicktemplate v1.6.3
74+
golang.org/x/mod v0.4.0
7275
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 // indirect
7376
golang.org/x/text v0.3.4 // indirect
7477
golang.org/x/tools v0.0.0-20210105210202-9ed45478a130

go.sum

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/testdata/rowserrcheck.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package testdata
33

44
import (
55
"database/sql"
6+
"fmt"
7+
"math/rand"
68
)
79

810
func RowsErrNotChecked(db *sql.DB) {
@@ -11,3 +13,53 @@ func RowsErrNotChecked(db *sql.DB) {
1113

1214
}
1315
}
16+
17+
func issue943_1() {
18+
db, err := sql.Open("postgres", "postgres://localhost:5432/postgres")
19+
if err != nil {
20+
panic(err)
21+
}
22+
defer db.Close()
23+
24+
var rows *sql.Rows
25+
if rand.Float64() < 0.5 {
26+
rows, err = db.Query("select 1")
27+
} else {
28+
rows, err = db.Query("select 2")
29+
}
30+
if err != nil {
31+
panic(err)
32+
}
33+
defer rows.Close()
34+
for rows.Next() {
35+
fmt.Println("new rows")
36+
}
37+
if err := rows.Err(); err != nil {
38+
panic(err)
39+
}
40+
}
41+
42+
func issue943_1() {
43+
db, err := sql.Open("postgres", "postgres://localhost:5432/postgres")
44+
if err != nil {
45+
panic(err)
46+
}
47+
defer db.Close()
48+
49+
var rows *sql.Rows
50+
if rand.Float64() < 0.5 {
51+
rows, err = db.Query("select 1") // ERROR "rows.Err must be checked"
52+
} else {
53+
rows, err = db.Query("select 2") // ERROR "rows.Err must be checked"
54+
}
55+
if err != nil {
56+
panic(err)
57+
}
58+
defer rows.Close()
59+
for rows.Next() {
60+
fmt.Println("new rows")
61+
}
62+
if err := rows.Err(); err != nil {
63+
panic(err)
64+
}
65+
}

0 commit comments

Comments
 (0)