New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rows.Err must be checked using rowserrcheck #945
Comments
I found a style for pass rowserrcheck rows, err := db.Query("some sql")
if err != nil {
// error handling
}
defer func() {
_ = rows.Close()
_ = rows.Err() // or modify return value
}
for rows.Next() {
// normal handling
} |
should be like this |
Guys, you fixed the linter error but didn't figure out the real problem in your code. rows, err := db.Query(....)
if err != nil {
return nil, err
}
for rows.Next() {
// scan row
}
return result, nil you have a big problem - rows.Next() returns false either when you've reached the end of data or you've gotten an read error. The second case you do not check and this leads you to the fact that only part of the data is returned. rows, err := db.Query(....)
if err != nil {
return nil, err
}
for rows.Next() {
// scan row
}
if err := rows.Err(); err != nil {
return nil, err
}
return result, nil |
It turns out `rows.Next()` can return false on error, avoiding error detection with `rows.Scan` See golangci/golangci-lint#945 Fix that. In particular, `QueryRowContext` with checking for `sql.ErrNowRows` is much simpler when expecting 0 or 1 results Mark two false positives when only wanting schema of `LIMIT 0` query
It turns out `rows.Next()` can return false on error, avoiding error detection with `rows.Scan` See golangci/golangci-lint#945 Fix that. In particular, `QueryRowContext` with checking for `sql.ErrNowRows` is much simpler when expecting 0 or 1 results Mark two false positives when only wanting schema of `LIMIT 0` query
It turns out `rows.Next()` can return false on error, avoiding error detection with `rows.Scan` See golangci/golangci-lint#945 Fix that. In particular, `QueryRowContext` with checking for `sql.ErrNowRows` is much simpler when expecting 0 or 1 results Mark two false positives when only wanting schema of `LIMIT 0` query
Thank you for creating the issue!
Please include the following information:
I upgrade my golangci-lint to 1.23.1 to check unclosed sql connection
for example i have this query:
but with this current version it keeps on display the error message
rows.Err must be checked (rowserrcheck)
despite of existing conditionon the code can someone validate this?
i found this one golang/go#24329 but it doesnt satisfy
me hoping to hear your reply
Version of golangci-lint
Config file
Go environment
Verbose output of running
The text was updated successfully, but these errors were encountered: