Skip to content

golangci/rowserrcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rowserrcheck

Important

This is a fork of rowserrcheck. This is a hard fork because rowserrcheck is a fork of bodyclose. GitHub does not allow forking two forks of the same repository.

rowserrcheck is a static analysis tool which checks whether sql.Rows.Err is correctly checked.

Install

go install github.com/golangci/rowserrcheck@latest

Analyzer

rowserrcheck validates whether *database/sql.Rows of sql query calls method rows.Err() such as below code.

rows, _ := db.Query("select id from tb") // Wrong case
if err != nil {
	// handle error
}
for rows.Next(){
	// handle rows
}

This code is wrong. You must check rows.Err when finished scan rows.

rows, _ := db.Query("select id from tb") // Wrong case
for rows.Next(){
	// handle rows
}
if rows.Err()!=nil{
	// handle err
}

In the GoDoc of sql.Rows this rule is clearly described.

If you forget this sentence, and unluckly an invaliad connection error happend when fetch data from database, rows.Next will return false, and you will get an incomplete data, and even it seems everything is ok. This will cause serious accident.

Thanks

Thanks for timakin.

About

Checks whether err of sql.Rows is checked.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Contributors