errcheck
errcheck copied to clipboard
Error return value is not checked (errcheck) for interface assertion
Hello,
seaguest@DEV:~/Work/monitor/test$ golangci-lint version
golangci-lint has version 1.51.2 built from 3e8facb4 on 2023-02-19T21:43:54Z
seaguest@DEV:~/Work/monitor/test$
seaguest@DEV:~/Work/monitor/test$
seaguest@DEV:~/Work/monitor/test$ cat t4.go
package main
import (
"errors"
)
var _ error = (*ValidationError)(nil)
type ValidationError struct {
Msg string
}
func (v *ValidationError) Error() string {
return v.Msg
}
func main() {
foo("huu")
}
func foo(a string) error {
if a == "a" {
return errors.New("OOPS")
}
return nil
}
seaguest@DEV:~/Work/monitor/test$ golangci-lint run -Eerrcheck
t4.go:7:5: Error return value is not checked (errcheck)
var _ error = (*ValidationError)(nil)
^
t4.go:18:5: Error return value is not checked (errcheck)
foo("huu")
^
There should not be error for
var _ error = (*ValidationError)(nil)
It seems related to https://github.com/kisielk/errcheck/pull/219
This problem exists because errcheck doesn't recognize the value of type conversion. It only checks if the result value is error type