-
Notifications
You must be signed in to change notification settings - Fork 16
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
Warning about comparisons for indirect errors #55
Comments
This might or might not be a dup of #49. Update: it is not. |
golangci-lint v1.54.2 comes with errorlint v1.4.4, which contains the fix [1] whitelisting all errno comparisons for errors coming from x/sys/unix. Thus, these annotations are no longer necessary. Remove those. Except, the errors that do not come directly from a function in unix package still need to be annotated (see [2]). [1] polyfloyd/go-errorlint#47 [2] polyfloyd/go-errorlint#55 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This is not specific to unix errors. Here is another example, for io.EOF: func read(r io.Reader) error {
var buf [1]byte
_, err := r.Read(buf[:])
return err
}
func CompareIoEOFIndirectly(r io.Reader) {
err := read(r)
if err != io.EOF {
fmt.Println(err)
}
} |
Hi! I have thought about this while developing the linter, but considered this to be too far enough from the original problem and too complex to solve. As you know, the linter uses a list of permitted function/error combinations to decide whether a raise an issue. But when an error is returned inside a function not part of this allowlist this of course does not work. A solution that achieves what you are suggesting would have to look inside the function being called and build a set of all errors being produced and match it against the list. At this point, I would suggest to use Another solution would be a feature to for custom additions to the allowlist so project specific functions known to be safe could be allowed. |
@polyfloyd I guess you are right -- any such function can in fact wrap an error. I do not consider this a bug, thus closing. |
The following code produces no warnings (since v1.4.4, which has #10 fixed).
but if we wrap unix.Rmdir into a function:
we still get the warning:
The text was updated successfully, but these errors were encountered: