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

ignores unhandled errors of methods #3976

Closed
5 tasks done
hebelsan opened this issue Jul 25, 2023 · 4 comments
Closed
5 tasks done

ignores unhandled errors of methods #3976

hebelsan opened this issue Jul 25, 2023 · 4 comments
Labels
question Further information is requested

Comments

@hebelsan
Copy link

Welcome

Description of the problem

My code has unhandled errors but running golangci-lint run has no output/finding.
However running errcheck which is enabled per default as sub-linter outputs:

main.go:6:11:	os.Remove("test")

When I manually write a function that returns an error and i put it in my code without handling the error it will be catched by golangci-lint run.
So it seems to ignore methods and only checks for functions, but that's just a wild guess...

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.53.3 built with go1.20.5 from 2dcd82f3 on 2023-06-15T10:50:11Z

Configuration

no custom flag:
$golangci-lint run

$golangci-lint help linters
Enabled by default linters:
errcheck: errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
gosimple (megacheck): Linter for Go source code that specializes in simplifying code [fast: false, auto-fix: false]
govet (vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
ineffassign: Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
staticcheck (megacheck): It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint. [fast: false, auto-fix: false]
typecheck: Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false]
unused (megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]

Go environment

$ go version && go env
go version go1.19.5 darwin/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/alex/Library/Caches/go-build"
GOENV="/Users/alex/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/alex/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/alex/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/alex/workspace/tests/lint/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/yv/2wbqgdnn1f3btm66bpdbp08m0000gn/T/go-build1442240389=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /Users/alex/workspace/tests/lint /Users/alex/workspace/tests /Users/alex/workspace /Users/I540852 /Users /]
INFO [lintersdb] Active 7 linters: [errcheck gosimple govet ineffassign staticcheck typecheck unused]
INFO [loader] Go packages loading at mode 575 (compiled_files|exports_file|imports|name|deps|files|types_sizes) took 150.966102ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 169.69µs
INFO [linters_context/goanalysis] analyzers took 1.462973115s with top 10 stages: buildir: 633.76638ms, ctrlflow: 155.681628ms, printf: 136.692872ms, fact_deprecated: 130.541631ms, SA5012: 99.74426ms, fact_purity: 94.649374ms, nilness: 87.96792ms, typedness: 81.677296ms, inspect: 39.021007ms, errcheck: 159.796µs
INFO [runner] Issues before processing: 1, after processing: 0
INFO [runner] Processors filtering stat (out/in): autogenerated_exclude: 1/1, exclude: 1/1, cgo: 1/1, skip_files: 1/1, skip_dirs: 1/1, filename_unadjuster: 1/1, identifier_marker: 1/1, path_prettifier: 1/1, exclude-rules: 0/1
INFO [runner] processing took 333.834µs with stages: path_prettifier: 118.973µs, autogenerated_exclude: 90.332µs, identifier_marker: 89.001µs, skip_dirs: 19.728µs, exclude-rules: 7.688µs, cgo: 1.316µs, nolint: 1.049µs, filename_unadjuster: 707ns, max_same_issues: 692ns, uniq_by_line: 649ns, fixer: 633ns, skip_files: 419ns, max_from_linter: 398ns, source_code: 367ns, exclude: 321ns, severity-rules: 314ns, diff: 300ns, path_shortener: 254ns, sort_results: 242ns, path_prefixer: 231ns, max_per_file_from_linter: 220ns
INFO [runner] linters took 889.617387ms with stages: goanalysis_metalinter: 889.169548ms
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 12 samples, avg is 138.3MB, max is 240.0MB
INFO Execution took 1.051132741s

Code example or link to a public repository

package main

import "os"

func main() {
    os.Remove("test")
    test()
}

func test() error {
    return nil
}

Validation

  • Yes, I've included all information above (version, config, etc.).
@hebelsan hebelsan added the bug Something isn't working label Jul 25, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Jul 25, 2023

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez
Copy link
Member

ldez commented Jul 25, 2023

Hello,

you have checked this box, can you give me the output of the errcheck linter?

@ldez ldez added dependencies Relates to an upstream dependency feedback required Requires additional feedback labels Jul 25, 2023
@hebelsan
Copy link
Author

hebelsan commented Jul 26, 2023

Hi,

For the example I posted errcheck returns:

main.go:6:11:	os.Remove("test")
main.go:7:6:	test()

whereas golangci-lint seems to ignore os.Remove("test") and only notifies for test()

@ldez ldez added question Further information is requested and removed bug Something isn't working feedback required Requires additional feedback dependencies Relates to an upstream dependency labels Jul 26, 2023
@ldez
Copy link
Member

ldez commented Jul 26, 2023

This report is ignored by default, this is the exclusion rule EXC0001.
It was flagged as "Almost all programs ignore errors on these functions and in most cases it's ok".

To show the report, you have to disable the default exclusions:

issues:
  exclude-use-default: false

or you have to disable this specific exclusion rule:

issues:
  include:
    - EXC0001

It will be changed at some point: #456 (comment)

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

No branches or pull requests

2 participants