golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
14.99k stars 1.35k forks source link

Running error: can't run linter goanalysis_metalinter #4482

Closed demoManito closed 3 months ago

demoManito commented 4 months ago

Welcome

Description of the problem

Pull the latest code and use make build. It cannot be exploded accordingly.

GoLang Version: 1.21.8 golangci-lint Version: latest master make build

Version of golangci-lint

```console $ golangci-lint --version # Paste output here golangci-lint has version (devel) built with go1.21.8 from (unknown, mod sum: "") on (unknown) ```

Configuration

```console # paste configuration file or CLI flags here ```

Go environment

```console $ go version && go env # paste output here ```

Verbose output of running

```console $ golangci-lint cache clean $ golangci-lint run -v # paste output here INFO [config_reader] Config search paths: [./] INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 10 linters: [errcheck forbidigo goimports gosimple govet ineffassign misspell staticcheck unused whitespace] INFO [loader] Go packages loading at mode 575 (name|types_sizes|compiled_files|deps|exports_file|files|imports) took 896.459292ms INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 70.753584ms INFO [linters_context/goanalysis] analyzers took 2m9.91934941s with top 10 stages: buildir: 14.901529871s, goimports: 5.670117284s, forbidigo: 5.642568598s, S1038: 2.781328369s, whitespace: 2.665187295s, directives: 2.568707869s, misspell: 2.506498657s, unused: 2.399164374s, isgenerated: 2.154990296s, errcheck: 1.803361748s ERRO [runner] Panic: httpresponse: package "chatroom" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 54483 [running]: runtime/debug.Stack() /Users/jesse/.gvm/gos/go1.21.8/src/runtime/debug/stack.go:24 +0x64 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1() /Users/jesse/GolandProjects/golangci-lint/pkg/golinters/goanalysis/runner_action.go:108 +0x224 panic({0x101d79820?, 0x10271c140?}) /Users/jesse/.gvm/gos/go1.21.8/src/runtime/panic.go:914 +0x218 go/types.(*Named).Obj(...) /Users/jesse/.gvm/gos/go1.21.8/src/go/types/named.go:295 golang.org/x/tools/go/analysis/passes/internal/analysisutil.IsNamedType({0x101ee5460?, 0x0?}, {0x1019b7503?, 0x100efaff4?}, {0x140046beab8?, 0x1?, 0x140046beb68?}) /Users/jesse/.gvm/pkgsets/go1.21.8/global/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/internal/analysisutil/util.go:123 +0x38 golang.org/x/tools/go/analysis/passes/httpresponse.isHTTPFuncOrMethodOnClient(0x140192e1810, 0x1?) /Users/jesse/.gvm/pkgsets/go1.21.8/global/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/httpresponse/httpresponse.go:122 +0x144 golang.org/x/tools/go/analysis/passes/httpresponse.run.func1({0x101ee4830?, 0x1400f49d6c0?}, 0x68?, {0x1401a49a400, 0x5, 0x10}) /Users/jesse/.gvm/pkgsets/go1.21.8/global/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/httpresponse/httpresponse.go:62 +0x58 golang.org/x/tools/go/ast/inspector.(*Inspector).WithStack(0x140085c6420, {0x140046bec88?, 0x1?, 0x14000e8a0f0?}, 0x14003033c98) /Users/jesse/.gvm/pkgsets/go1.21.8/global/pkg/mod/golang.org/x/tools@v0.19.0/go/ast/inspector/inspector.go:148 +0x168 golang.org/x/tools/go/analysis/passes/httpresponse.run(0x1401b9396c0) /Users/jesse/.gvm/pkgsets/go1.21.8/global/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/httpresponse/httpresponse.go:57 +0x104 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x140054888b0) /Users/jesse/GolandProjects/golangci-lint/pkg/golinters/goanalysis/runner_action.go:190 +0x99c github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2() /Users/jesse/GolandProjects/golangci-lint/pkg/golinters/goanalysis/runner_action.go:112 +0x20 github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x14001d4c190, {0x101a01a2d, 0xc}, 0x14004472730) /Users/jesse/GolandProjects/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x1013975c0?) /Users/jesse/GolandProjects/golangci-lint/pkg/golinters/goanalysis/runner_action.go:111 +0x78 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x140054888b0) /Users/jesse/GolandProjects/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb0 created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 403 /Users/jesse/GolandProjects/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x184 WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: httpresponse: package "chatroom" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference INFO [runner] processing took 1.292µs with stages: max_same_issues: 500ns, skip_dirs: 166ns, cgo: 125ns, path_prefixer: 42ns, severity-rules: 42ns, identifier_marker: 42ns, autogenerated_exclude: 42ns, path_prettifier: 42ns, diff: 42ns, max_from_linter: 42ns, sort_results: 42ns, source_code: 42ns, skip_files: 41ns, uniq_by_line: 41ns, nolint: 41ns, fixer: 0s, exclude-rules: 0s, filename_unadjuster: 0s, exclude: 0s, max_per_file_from_linter: 0s, path_shortener: 0s INFO [runner] linters took 4.73555075s with stages: goanalysis_metalinter: 4.735327791s ERRO Running error: can't run linter goanalysis_metalinter goanalysis_metalinter: httpresponse: package "chatroom" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference INFO Memory: 59 samples, avg is 533.3MB, max is 936.1MB INFO Execution took 5.711658375s ```

A minimal reproducible example or link to a public repository

```go // add your code here ```

Validation

boring-cyborg[bot] commented 4 months ago

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

ldez commented 4 months ago

Hello,

can you provide a reproducible code example and your configuration?

ldez commented 4 months ago

This issue doesn't provide:

With the stacktrace, the only things that I can know are it may be related to the govet rule httpresponse or golang.org/x/tools@v0.19.0.

Without more information, it can take days to find out how to recreate the problem (if the problem can be recreated) and how to fix it.


If you are facing the same problem, the best way to contribute is to provide the following information:

A code example or link to a public repository.

golangci-lint --version
# or exact commit reference
cat .golangci.yml
go version && go env
golangci-lint cache clean
golangci-lint run -v
firelizzard18 commented 4 months ago

I have this same issue on https://gitlab.com/accumulatenetwork/accumulate/ when I update to golangci-lint bleeding edge (for the new plugin system). Once I work around it for production I'll try to make a repro branch.

Ultimately it appears there's a bug in golang.org/x/tools.

firelizzard18 commented 4 months ago

golangci-repro-4482 reproduces the panic on my PC. Reverting golang.org/x/tools to v0.18.0 resolves the issue. Here's the full log:

log
INFO [config_reader] Config search paths: [./ /home/firelizzard/src/Accumulate/accumulate /home/firelizzard/src/Accumulate /home/firelizzard/src /home/firelizzard /home /] 
INFO [config_reader] Used config file .golangci.yml 
INFO Loaded : rangevarref                         
INFO Loaded : noprint                             
INFO Loaded : nodebug                             
INFO [lintersdb] Active 1 linters: [govet]        
INFO [loader] Go packages loading at mode 575 (name|compiled_files|deps|exports_file|files|imports|types_sizes) took 448.562894ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 45.95519ms 
INFO [linters_context/goanalysis] analyzers took 636.641834ms with top 10 stages: inspect: 117.639198ms, printf: 89.964436ms, ctrlflow: 62.623472ms, copylocks: 53.980913ms, assign: 29.201073ms, lostcancel: 26.764156ms, bools: 21.786709ms, composites: 18.945616ms, unsafeptr: 17.460426ms, unreachable: 15.820847ms 
ERRO [runner] Panic: httpresponse: package "simulator" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 28424 [running]:
runtime/debug.Stack()
        /home/firelizzard/sdk/go1.22.1/src/runtime/debug/stack.go:24 +0x5e
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.3-0.20240311192827-d18acc5b51ed/pkg/golinters/goanalysis/runner_action.go:108 +0x277
panic({0x16e86a0?, 0x2327480?})
        /home/firelizzard/sdk/go1.22.1/src/runtime/panic.go:770 +0x132
go/types.(*Named).Obj(...)
        /home/firelizzard/sdk/go1.22.1/src/go/types/named.go:295
golang.org/x/tools/go/analysis/passes/internal/analysisutil.IsNamedType({0x1afa470?, 0x0?}, {0x185e739, 0x8}, {0xc0027ebaf8, 0x1, 0x928645?})
        /home/firelizzard/go/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/internal/analysisutil/util.go:123 +0x49
golang.org/x/tools/go/analysis/passes/httpresponse.isHTTPFuncOrMethodOnClient(0xc00dd04240, 0xc014064100?)
        /home/firelizzard/go/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/httpresponse/httpresponse.go:122 +0xfb
golang.org/x/tools/go/analysis/passes/httpresponse.run.func1({0x1af9b10?, 0xc00cdc7c80?}, 0x10?, {0xc014064100, 0xc, 0x10})
        /home/firelizzard/go/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/httpresponse/httpresponse.go:62 +0x73
golang.org/x/tools/go/ast/inspector.(*Inspector).WithStack(0xc0124d1d88, {0xc0034c64b8?, 0x2353000?, 0x600?}, 0xc00164bcc8)
        /home/firelizzard/go/pkg/mod/golang.org/x/tools@v0.19.0/go/ast/inspector/inspector.go:148 +0x188
golang.org/x/tools/go/analysis/passes/httpresponse.run(0xc01df8bc70)
        /home/firelizzard/go/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/httpresponse/httpresponse.go:57 +0x112
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc00353b5b0)
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.3-0.20240311192827-d18acc5b51ed/pkg/golinters/goanalysis/runner_action.go:190 +0xa02
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.3-0.20240311192827-d18acc5b51ed/pkg/golinters/goanalysis/runner_action.go:112 +0x17
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00259e910, {0x18a8df4, 0xc}, 0xc0034c6748)
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.3-0.20240311192827-d18acc5b51ed/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc00045e2a0?)
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.3-0.20240311192827-d18acc5b51ed/pkg/golinters/goanalysis/runner_action.go:111 +0x7a
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc00353b5b0)
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.3-0.20240311192827-d18acc5b51ed/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xa8
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 800
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.3-0.20240311192827-d18acc5b51ed/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x205 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: httpresponse: package "simulator" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference 
INFO [runner] processing took 1.973µs with stages: max_same_issues: 474ns, skip_dirs: 237ns, nolint: 167ns, max_from_linter: 131ns, cgo: 105ns, autogenerated_exclude: 97ns, exclude-rules: 95ns, skip_files: 94ns, identifier_marker: 94ns, path_prettifier: 90ns, filename_unadjuster: 89ns, fixer: 37ns, diff: 31ns, severity-rules: 30ns, uniq_by_line: 30ns, sort_results: 30ns, exclude: 30ns, source_code: 30ns, path_shortener: 28ns, path_prefixer: 27ns, max_per_file_from_linter: 27ns 
INFO [runner] linters took 554.127017ms with stages: goanalysis_metalinter: 554.104557ms 
ERRO Running error: can't run linter goanalysis_metalinter
goanalysis_metalinter: httpresponse: package "simulator" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference 
INFO Memory: 12 samples, avg is 188.0MB, max is 536.2MB 
INFO Execution took 1.051656194s
ldez commented 4 months ago

Thank you, as a temporary fix, I will revert golang.org/x/tools

ldez commented 4 months ago

sadly we cannot revert easily... :cry:

It's related to this commit https://github.com/golang/tools/commit/c111c4dfa

I know where the bug is but I don't find a way to create a minimal reproducible example.

ldez commented 4 months ago

I submitted a bug report https://github.com/golang/go/issues/66259 @firelizzard18 I linked your branch. Can you remove the plugin section of the .golangci.yml inside this branch?


The problem is related to func ChainFromJSON(s *string) (*[32]byte, error) {, the *[32]byte produces the panic :thinking:


I found the problem -> https://github.com/golang/go/issues/66259#issuecomment-1990261780

firelizzard18 commented 4 months ago

I stripped down .golangci.yml to the minimum needed to reproduce the issue.

Thanks for your work on tracing this to the root cause.

ldez commented 4 months ago

I created a minimal example with only 2 files (it was not fun to remove all your code file by file and line by line :smile:)

https://github.com/golang/go/issues/66259#issuecomment-1992617964

The feedback on the Go issue is sparse, the CL attached will fix the problem but we have to wait

ldez commented 3 months ago

Fixed by #4620

demoManito commented 3 months ago

thanks @ldez

szaydel commented 2 weeks ago

It would be nice to improve visibility into this. I have been chasing my tail for a while with an issue which ultimately stems from the fact that this package: github.com/awnumar/memcall does not actually support Solaris and illumos. I was running into an issue where this package is actually a dependency of a dependency, and it was not clear to me that the failure was a result of the package not being buildable. The fix is quite straight-forward and I am going to try to get it upstreamed, but more to the point, the way I figured out what is going on is by running this instead of the normal golangci-lint run with a saved config file:

$ golangci-lint run -E typecheck .
main.go:6:2: could not import github.com/awnumar/memcall (-: # github.com/awnumar/memcall
../../go/pkg/mod/github.com/szaydel/memcall@v1.0.0-test/memcall_unix.go:15:23: undefined: unix.MADV_DONTDUMP) (typecheck)
    "github.com/awnumar/memcall"
    ^

The reason you are seeing szaydel in the path is because I used a replace directive in the go.mod file. It certainly would have been easier to debug this if I saw this message. Instead, what I was seeing is the following:

... snip ...
WARN [runner] Can't run linter goanalysis_metalinter: findcall: failed to load package memcall: could not load export data: no export data for "github.com/awnumar/memcall"
... snip ...
ERRO Running error: can't run linter goanalysis_metalinter
findcall: failed to load package memcall: could not load export data: no export data for "github.com/awnumar/memcall"
... snip ...
ldez commented 2 weeks ago

https://golangci-lint.run/welcome/faq/#why-do-you-have-typecheck-errors

szaydel commented 2 weeks ago

Thank you for the link @ldez. My main issue was that when I ran golangci-lint the way it would normally run under CI, this was not visible. As soon as I isolated the problem with the help of -E typecheck it became clear what is going on.

From this output, I could not tell what is going on:

WARN [runner] Can't run linter goanalysis_metalinter: findcall: failed to load package memcall: could not load export data: no export data for "github.com/awnumar/memcall"
ldez commented 2 weeks ago

-E typecheck doesn't nothing (except if you are using a very old version of golangci-lint) because typecheck can not be enabled or disabled because it's not a linter.

szaydel commented 2 weeks ago

That's interesting. I am not running an old version of golangci-lint. Perhaps this is just a matter of the configuration leading to the error being hidden, or the fact that in my dummy project this is a direct dependency as opposed to my bigger project where this is a dependency of a dependency?

$ golangci-lint version
golangci-lint has version 1.59.1 built with go1.22.3 from 1a55854a on 2024-06-09T18:08:33Z
ldez commented 2 weeks ago

The only effect is a kind of side effect: if you are using disable-all then -E will override your enable configuration to "enable" only typecheck. Technically it's the same thing as disabling all the linters, so you will just have typecheck.

EDIT: I said something wrong because -E append (and not override) to the existing enable configuration.

szaydel commented 2 weeks ago

I guess I am still not sure what is going on. I am going to see if I can figure out why I am observing different outcomes. The best I can come-up with is the difference in package being a direct as opposed to an indirect dependency. Thank you for the feedback @ldez.