errcheck
errcheck copied to clipboard
Error must be checked before other code run
package main
import (
"errors"
"fmt"
"os"
)
type Stu struct {
Age int
}
func AAA() (*Stu, error) {
return nil, errors.New("error here")
}
func BBB() (v int, err error) {
stu, err := AAA() //lint must return if err != nil
stu.Age = 1
return
}
func main() {
res, err := BBB()
fmt.Fprintln(os.Stdout, res, err)
}
this code can't check the err not return, so it panic.
I hope that this situation can be warned, or whether it is turned on or not controlled by parameters
Hm, there could very well be legitimate cases where one needs to run something before checking for error. For example, the one I had was where I wanted to issue a log statement regardless of whether error was nil or not.
For now, closing due to inactivity from the OP