Skip to content
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

implement whilelist for switch #54

Open
kolyshkin opened this issue Aug 25, 2023 · 2 comments
Open

implement whilelist for switch #54

kolyshkin opened this issue Aug 25, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@kolyshkin
Copy link
Contributor

The following legitimate comparison using switch statement

func SwitchOnUnixErrors() {
       err := unix.Rmdir("somepath")
       switch err {
       case unix.ENOENT:
               return
       case unix.EPERM:
               return
       }
       fmt.Println(err)
}

results in a warning:

switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors

Apparently, whitelist of allowed direct comparisons, as implemented in allowed.go, is not used when analysing switch statements.

@kolyshkin
Copy link
Contributor Author

Another example:

func SwitchIoEOF(r io.Reader) {
        var buf [4096]byte
        _, err := r.Read(buf[:])
        switch err {
        case nil:
                return
        case io.EOF:
                return
        }
        fmt.Println(err)
}

kolyshkin added a commit to kolyshkin/sys that referenced this issue Aug 25, 2023
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. Remove the annotation that is no longer needed.

Unfortunately, switch on a bare unix error (in mountinfo) still needs to
be annotated (see [2]).

[1] polyfloyd/go-errorlint#47
[2] polyfloyd/go-errorlint#54

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/sys that referenced this issue Aug 25, 2023
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. Remove the annotation that is no longer needed.

Unfortunately, switch on a bare unix error (in mountinfo) still needs to
be annotated (see [2]).

[1] polyfloyd/go-errorlint#47
[2] polyfloyd/go-errorlint#54

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/sys that referenced this issue Aug 25, 2023
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. Remove the annotation that is no longer needed.

Unfortunately, switch on a bare unix error (in mountinfo) still needs to
be annotated (see [2]).

[1] polyfloyd/go-errorlint#47
[2] polyfloyd/go-errorlint#54

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@polyfloyd
Copy link
Owner

Yes, that should be a valid comparison. The allowlist must apply to switch statements too

@polyfloyd polyfloyd added bug Something isn't working help wanted Extra attention is needed labels Sep 2, 2023
kolyshkin added a commit to kolyshkin/sys that referenced this issue Oct 27, 2023
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. Remove the annotation that is no longer needed.

Unfortunately, switch on a bare unix error (in mountinfo) still needs to
be annotated (see [2]).

[1] polyfloyd/go-errorlint#47
[2] polyfloyd/go-errorlint#54

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants