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

Error checking when the client is closed is not captured #609

Closed
zhqqqy opened this issue Jul 12, 2019 · 0 comments
Closed

Error checking when the client is closed is not captured #609

zhqqqy opened this issue Jul 12, 2019 · 0 comments

Comments

@zhqqqy
Copy link

zhqqqy commented Jul 12, 2019

Thank you for creating the issue!

Please include the following information:

  1. golangci-lint has version 1.17.1
  2. no config
  3. go version go1.12.5 darwin/amd64

my code is

func main() {
    c := newKvClient("")
    c.Close()
}

func newKvClient(addr string) *redis.Client {
    client := redis.NewClient(&redis.Options{
        Addr: addr,
    })
     client.Ping().Result()

    return client
}
  1. Verbose output of running: golangci-lint run -v

INFO [config_reader] Config search paths: [./ /Users/zhaohq/go/src/sonargo-test /Users/zhaohq/go/src /Users/zhaohq/go /Users/zhaohq /Users /]
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]
INFO [lintersdb] Optimized sublinters [staticcheck gosimple unused] into metalinter megacheck
INFO [loader] Go packages loading at mode load types and syntax took 1.470327816s
INFO [loader] SSA repr building timing: packages building 9.962618ms, total 101.292279ms
INFO [runner] worker.4 took 923.948µs with stages: structcheck: 322.505µs, varcheck: 299.842µs, deadcode: 281.891µs, typecheck: 10.47µs
INFO [runner] worker.1 took 1.613303ms with stages: errcheck: 911.329µs, ineffassign: 525.108µs
main.go:21:26: Error return value of (*github.com/go-redis/redis.StatusCmd).Result is not checked (errcheck)
client.Ping().Result()
^
INFO [runner] worker.3 took 271.552451ms with stages: govet: 271.546439ms
INFO [runner] worker.2 took 760.285582ms with stages: megacheck: 760.264137ms
INFO [runner] Workers idle times: #1: 758.658684ms, #3: 488.723978ms, #4: 759.063965ms
INFO [runner] Issues before processing: 2, after processing: 1
INFO [runner] processing took 181.582759ms with stages: nolint: 119.140907ms, source_code: 59.228038ms, exclude: 2.194487ms, skip_dirs: 506.979µs, cgo: 350.218µs, identifier_marker: 90.421µs, autogenerated_exclude: 45.13µs, max_same_issues: 7.018µs, uniq_by_line: 4.952µs, path_prettifier: 4.288µs, path_shortener: 3.108µs, max_from_linter: 2.814µs, filename_unadjuster: 1.449µs, max_per_file_from_linter: 1.148µs, diff: 779ns, exclude-rules: 588ns, skip_files: 435ns
INFO File cache stats: 1 entries of total size 333B
INFO Memory: 27 samples, avg is 198.2MB, max is 406.0MB
INFO Execution took 2.542864033s

But the return value of c.Close() error is not checked. just checked client.Ping().Result()

@Helcaraxan
Copy link
Contributor

This is actually expected. An excerpt from golangci-lint run --help:

$ golangci-lint run --help
[...]
      --exclude-use-default         Use or not use default excludes:
                                      # errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
                                      - Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked
[...]

If you want this error to be captured you can use --exclude-use-default=false when running the linter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants