go-errorlint icon indicating copy to clipboard operation
go-errorlint copied to clipboard

Not all of the issues about comparing err with gorm.ErrRecordNotFound using '==' directly can be detected by errorlint.

Open dumbFeng opened this issue 3 years ago • 2 comments

Version of golangci-lint:golangci-lint has version 1.44.2 built from d58dbde on 2022-02-17T18:35:00Z

Version of Go:v1.14

Issue: Not all of the issues about comparing err with gorm.ErrRecordNotFound using '==' directly can be detected by errorlint.

dumbFeng avatar Apr 18 '22 09:04 dumbFeng

For example:

err := gorm.DB.First(&model).Error
if err == gorm.ErrRecordNotFound{
  //...
}

The code above cannot be detected by errorlint.

dumbFeng avatar Apr 18 '22 09:04 dumbFeng

I do not seem to be able to reproduce this:

package main

import "gorm.io/gorm"

type MyModel struct {
	ID int
}

func main() {
	db, _ := gorm.Open(nil, nil)

	var model MyModel
	err := db.First(&model).Error
	if err == gorm.ErrRecordNotFound {
		//...
	}
}

It works fine.

golangci-lint also reports it. Could you update your linter to v1.45.2?

polyfloyd avatar Apr 22 '22 14:04 polyfloyd