golangci / golangci-lint

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

erro: 'can't run linter goanalysis_metalinter: buildssa': failed to load package cmd: could not load export data: no export data for "..." #3546

Closed acgreek closed 1 year ago

acgreek commented 1 year ago

Welcome

Description of the problem

I have found similar issues reported, though they are all 'closed' and reading through them I didn't find a solution that worked for me. I was able to find that I could make the issue go-away by disabling the following golangci-lint plugin: govet, megacheck, revive stylecheck, contextcheck, exhaustive

So this is also a feature request that when a plugin fails, it should say which plugin failed. This would save a user like myself from have to disable plugins in blocks until I find all the plugins that don't work. Also the error message is not very useful in saying what is wrong

Version of golangci-lint

```console $ golangci-lint --version golangci-lint has version 1.50.1 built from 8926a95f on 2022-10-22T10:50:47Z ```

Configuration file

This is the not working .golangci.yaml: ```console $ cat .golangci.yml # This file contains all available configuration options # with their default values. # options for analysis running run: # timeout for analysis, e.g. 30s, 5m, default is 1m deadline: 3m # include test files or not, default is true tests: false # which dirs to skip: they won't be analyzed; # can use regexp here: generated.*, regexp is applied on full path; # default value is empty list, but next dirs are always skipped independently # from this option's value: # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ skip-dirs: - pkg/api - vendor/ # which files to skip: they will be analyzed, but issues from them # won't be reported. Default value is empty list, but there is # no need to include all autogenerated files, we confidently recognize # autogenerated files. If it's not please let us know. skip-files: - ".*\\.my\\.go$" - lib/bad.go # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": # If invoked with -mod=readonly, the go command is disallowed from the implicit # automatic updating of go.mod described above. Instead, it fails when any changes # to go.mod are needed. This setting is most useful to check that go.mod does # not need updates, such as in a continuous integration and testing system. # If invoked with -mod=vendor, the go command assumes that the vendor # directory holds the correct copies of dependencies and ignores # the dependency descriptions in go.mod. #modules-download-mode: readonly|release|vendor # output configuration options output: # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" format: colored-line-number # print lines of code with issue, default is true print-issued-lines: true # print linter name in the end of issue text, default is true print-linter-name: true # all available settings of specific linters linters-settings: errcheck: # report about not checking of errors in type assetions: `a := b.(MyStruct)`; # default is false: such cases aren't reported by default. check-type-assertions: false # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; # default is false: such cases aren't reported by default. check-blank: false # [deprecated] comma-separated list of pairs of the form pkg:regex # the regex is used to ignore names within pkg. (default "fmt:.*"). # see https://github.com/kisielk/errcheck#the-deprecated-method for details ignore: fmt:.*,io/ioutil:^Read.* # path to a file containing a list of functions to exclude from checking # see https://github.com/kisielk/errcheck#excluding-functions for details # exclude: /path/to/file.txt funlen: lines: 150 statements: 75 govet: # report about shadowed variables check-shadowing: false golint: # minimal confidence for issues, default is 0.8 min-confidence: 0.8 gofmt: # simplify code: gofmt with `-s` option, true by default simplify: true goimports: # put imports beginning with prefix after 3rd-party packages; # it's a comma-separated list of prefixes #local-prefixes: github.com/org/project gocyclo: # minimal code complexity to report, 30 by default (but we recommend 10-20) min-complexity: 25 maligned: # print struct with more effective memory layout or not, false by default suggest-new: true dupl: # tokens count to trigger issue, 150 by default threshold: 100 goconst: # minimal length of string constant, 3 by default min-len: 3 # minimal occurrences count to trigger, 3 by default min-occurrences: 3 depguard: list-type: blacklist include-go-root: false packages: - github.com/davecgh/go-spew/spew misspell: # Correct spellings using locale preferences for US or UK. # Default is to use a neutral variety of English. # Setting locale to US will correct the British spelling of 'colour' to 'color'. locale: US ignore-words: - someword - mitre lll: # max line length, lines longer will be reported. Default is 120. # '\t' is counted as 1 character by default, and can be changed with the tab-width option line-length: 140 # tab width in spaces. Default to 1. tab-width: 1 unused: # treat code as a program (not a library) and report unused exported identifiers; default is false. # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: # if it's called for subdir of a project it can't find funcs usages. All text editor integrations # with golangci-lint call it on a directory with the changed file. check-exported: false unparam: # Inspect exported functions, default is false. Set to true if no external program/library imports your code. # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: # if it's called for subdir of a project it can't find external interfaces. All text editor integrations # with golangci-lint call it on a directory with the changed file. check-exported: false nakedret: # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 max-func-lines: 30 prealloc: # XXX: we don't recommend using this linter before doing performance profiling. # For most programs usage of prealloc will be a premature optimization. # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. # True by default. simple: true range-loops: true # Report preallocation suggestions on range loops, true by default for-loops: false # Report preallocation suggestions on for loops, false by default gocritic: # Which checks should be enabled; can't be combined with 'disabled-checks'; # See https://go-critic.github.io/overview#checks-overview # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` # By default list of stable checks is used. enabled-checks: # - rangeValCopy # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty disabled-checks: - regexpMust - ifElseChain # subject to annoying FPs due to naive static analysis # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks. # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". enabled-tags: - performance settings: # settings passed to gocritic captLocal: # must be valid enabled check name paramsOnly: true rangeValCopy: sizeThreshold: 32 linters: enable: - containedctx - decorder - depguard - dogsled - dupl # - dupword // not in u - errcheck - errname - execinquery # - exhaustruct - exportloopref - funlen - gochecknoglobals - gochecknoinits - gocognit - goconst - gocritic - gocyclo - godot - godox - goerr113 - gofmt - goimports - gomnd - gomodguard - goprintffuncname - gosec - govet - lll - megacheck - misspell - nakedret - nestif - nolintlint - prealloc - revive - stylecheck - testpackage - unconvert - unused - unparam - whitespace disable: - wsl - scopelint - varcheck - structcheck - deadcode - typecheck presets: - bugs - unused fast: false ``` And this is the working .golangci.yaml: ```console # This file contains all available configuration options # with their default values. # options for analysis running run: # timeout for analysis, e.g. 30s, 5m, default is 1m deadline: 3m # include test files or not, default is true tests: false # which dirs to skip: they won't be analyzed; # can use regexp here: generated.*, regexp is applied on full path; # default value is empty list, but next dirs are always skipped independently # from this option's value: # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ skip-dirs: - pkg/api - vendor/ # which files to skip: they will be analyzed, but issues from them # won't be reported. Default value is empty list, but there is # no need to include all autogenerated files, we confidently recognize # autogenerated files. If it's not please let us know. skip-files: - ".*\\.my\\.go$" - lib/bad.go # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": # If invoked with -mod=readonly, the go command is disallowed from the implicit # automatic updating of go.mod described above. Instead, it fails when any changes # to go.mod are needed. This setting is most useful to check that go.mod does # not need updates, such as in a continuous integration and testing system. # If invoked with -mod=vendor, the go command assumes that the vendor # directory holds the correct copies of dependencies and ignores # the dependency descriptions in go.mod. #modules-download-mode: readonly|release|vendor # output configuration options output: # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" format: colored-line-number # print lines of code with issue, default is true print-issued-lines: true # print linter name in the end of issue text, default is true print-linter-name: true # all available settings of specific linters linters-settings: errcheck: # report about not checking of errors in type assetions: `a := b.(MyStruct)`; # default is false: such cases aren't reported by default. check-type-assertions: false # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; # default is false: such cases aren't reported by default. check-blank: false # [deprecated] comma-separated list of pairs of the form pkg:regex # the regex is used to ignore names within pkg. (default "fmt:.*"). # see https://github.com/kisielk/errcheck#the-deprecated-method for details ignore: fmt:.*,io/ioutil:^Read.* # path to a file containing a list of functions to exclude from checking # see https://github.com/kisielk/errcheck#excluding-functions for details # exclude: /path/to/file.txt funlen: lines: 150 statements: 75 govet: # report about shadowed variables check-shadowing: false golint: # minimal confidence for issues, default is 0.8 min-confidence: 0.8 gofmt: # simplify code: gofmt with `-s` option, true by default simplify: true goimports: # put imports beginning with prefix after 3rd-party packages; # it's a comma-separated list of prefixes #local-prefixes: github.com/org/project gocyclo: # minimal code complexity to report, 30 by default (but we recommend 10-20) min-complexity: 25 maligned: # print struct with more effective memory layout or not, false by default suggest-new: true dupl: # tokens count to trigger issue, 150 by default threshold: 100 goconst: # minimal length of string constant, 3 by default min-len: 3 # minimal occurrences count to trigger, 3 by default min-occurrences: 3 depguard: list-type: blacklist include-go-root: false packages: - github.com/davecgh/go-spew/spew misspell: # Correct spellings using locale preferences for US or UK. # Default is to use a neutral variety of English. # Setting locale to US will correct the British spelling of 'colour' to 'color'. locale: US ignore-words: - someword - mitre lll: # max line length, lines longer will be reported. Default is 120. # '\t' is counted as 1 character by default, and can be changed with the tab-width option line-length: 140 # tab width in spaces. Default to 1. tab-width: 1 unused: # treat code as a program (not a library) and report unused exported identifiers; default is false. # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: # if it's called for subdir of a project it can't find funcs usages. All text editor integrations # with golangci-lint call it on a directory with the changed file. check-exported: false unparam: # Inspect exported functions, default is false. Set to true if no external program/library imports your code. # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: # if it's called for subdir of a project it can't find external interfaces. All text editor integrations # with golangci-lint call it on a directory with the changed file. check-exported: false nakedret: # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 max-func-lines: 30 prealloc: # XXX: we don't recommend using this linter before doing performance profiling. # For most programs usage of prealloc will be a premature optimization. # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. # True by default. simple: true range-loops: true # Report preallocation suggestions on range loops, true by default for-loops: false # Report preallocation suggestions on for loops, false by default gocritic: # Which checks should be enabled; can't be combined with 'disabled-checks'; # See https://go-critic.github.io/overview#checks-overview # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` # By default list of stable checks is used. enabled-checks: # - rangeValCopy # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty disabled-checks: - regexpMust - ifElseChain # subject to annoying FPs due to naive static analysis # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks. # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". enabled-tags: - performance settings: # settings passed to gocritic captLocal: # must be valid enabled check name paramsOnly: true rangeValCopy: sizeThreshold: 32 linters: enable: - containedctx - decorder - depguard - dogsled - dupl # - dupword // not in u - errcheck - errname - execinquery # - exhaustruct - exportloopref - funlen - gochecknoglobals - gochecknoinits - gocognit - goconst - gocritic - gocyclo - godot - godox - goerr113 - gofmt - goimports - gomnd - gomodguard - goprintffuncname - gosec - lll - misspell - nakedret - nestif - nolintlint - prealloc - testpackage - unconvert - unused - unparam - whitespace disable: - govet - megacheck - revive - stylecheck - wsl - scopelint - varcheck - structcheck - deadcode - typecheck - contextcheck - exhaustive presets: - bugs - unused fast: false ```

Go environment

```console $ go version && go env go version go1.18.10 linux/amd64 GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="-buildvcs=false" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/go/pkg/mod" GONOPROXY="" GONOSUMDB="removed.io/*,removed.io/*" GOOS="linux" GOPATH="/go" GOPRIVATE="" GOPROXY="https://removed/" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18.10" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/code/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3385784503=/tmp/go-build -gno-record-gcc-switches" ```

Verbose output of running

```console $ golangci-lint cache clean $ golangci-lint run -v INFO [config_reader] Config search paths: [./ /code / /root] INFO [config_reader] Used config file .golangci.yaml INFO [lintersdb] Active 58 linters: [asasalint asciicheck bidichk bodyclose containedctx contextcheck decorder depguard dogsled dupl durationcheck errcheck errchkjson errname errorlint execinquery exhaustive exportloopref funlen gochecknoglobals gochecknoinits gocognit goconst gocritic gocyclo godot godox goerr113 gofmt goimports gomnd gomodguard goprintffuncname gosec gosimple govet ineffassign lll loggercheck makezero misspell nakedret nestif nilerr noctx nolintlint prealloc reassign revive rowserrcheck sqlclosecheck staticcheck stylecheck testpackage unconvert unparam unused whitespace] INFO [lintersdb] Active presets: [bugs unused] INFO [loader] Go packages loading at mode 575 (imports|types_sizes|compiled_files|deps|files|exports_file|name) took 10.425033s INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 77.176ms INFO [linters_context/goanalysis] analyzers took 1m21.284369s with top 10 stages: buildir: 33.892112s, buildssa: 28.023601s, gocritic: 3.005592s, exhaustive: 2.4384s, inspect: 2.335095s, ctrlflow: 1.881358s, fact_deprecated: 1.825049s, printf: 1.522754s, nilness: 1.177379s, fact_purity: 1.160215s WARN [runner] Can't run linter goanalysis_metalinter: buildssa: failed to load package connectionstate: could not load export data: no export data for "code.8labs.io/apps/data-ingest/taegis/endpoints/endpoint-sdk/service/connectionstate" WARN [linters_context] rowserrcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649. WARN [linters_context] sqlclosecheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649. INFO [runner] processing took 756µs with stages: diff: 229µs, path_shortener: 144µs, sort_results: 114µs, uniq_by_line: 35µs, filename_unadjuster: 33µs, max_same_issues: 26µs, max_per_file_from_linter: 24µs, exclude-rules: 22µs, max_from_linter: 14µs, path_prefixer: 14µs, autogenerated_exclude: 12µs, nolint: 12µs, source_code: 11µs, severity-rules: 10µs, skip_files: 10µs, cgo: 10µs, skip_dirs: 10µs, path_prettifier: 9µs, identifier_marker: 9µs, exclude: 8µs INFO [runner] linters took 18.805333s with stages: goanalysis_metalinter: 18.800893s, rowserrcheck: 468µs, sqlclosecheck: 122µs ERRO Running error: 1 error occurred: * can't run linter goanalysis_metalinter: buildssa: failed to load package removed: could not load export data: no export data for "remove/path" INFO Memory: 291 samples, avg is 310.3MB, max is 686.5MB INFO Execution took 29.327421s ```

Code example or link to a public repository

```go // add your code here ```
boring-cyborg[bot] commented 1 year ago

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

ldez commented 1 year ago

Hello,

can you provide a minimal reproducible example?

buildssa is related to something shared between linters (linters are not plugins) so we detected which linter is affected by something like that. The SSA analysis is done only when at least one linter uses SSA.

Note: I recommend updating your go version to at least go1.19.

acgreek commented 1 year ago

Unfortunately, I don't see how I can provide you a useful example given that my companies code is not public domain and my change that resulted in finding this issue is massive

ldez commented 1 year ago

So I'm sorry, but without a reproducible example, as the error doesn't contain any information, I'm not able to diagnose or fix your problem.

acgreek commented 1 year ago

ok, when I have some free time. I'll see what I can do

RangelReale commented 1 year ago

I'm having exactly the same error message since today. We use Go 1.17 and golangci-lint 1.45. What is an export data?

evel=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: buildir: failed to load package mapper: could not load export data: no export data for \"xxx.com/pkg/mapper\"
RangelReale commented 1 year ago

found the problem, it is the same as #3391, that folder has compilation errors, the code must compile for golangci-lint to work properly.

ldez commented 1 year ago

Fixed by #3591

SnowWarri0r commented 1 year ago

I have this problem when i use goland file watcher,but if i input command in terminal it works fine.i don't know what to do to solve this problem. my goland version is 2023.1 golangci-lint version is 1.52.2 here is my log

level=info msg="[config_reader] Config search paths: [./ D:\\workspace\\go\\goframe D:\\workspace\\go D:\\workspace D:\\ C:\\Users\\admin]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 11 linters: [contextcheck errorlint ginkgolinter gocheckcompilerdirectives gofmt goimports gosec ineffassign lll nilerr wsl]"
level=info msg="[loader] Go packages loading at mode 575 (exports_file|name|compiled_files|deps|files|imports|types_sizes) took 1.3544023s"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 628.3µs"
level=info msg="[linters_context/goanalysis] analyzers took 0s with top 10 stages: contextcheck: 0s, gosec: 0s, gocheckcompilerdirectives: 0s, gofmt: 0s, errorlint: 0s, goimports: 0s, nilerr: 0s, buildssa: 0s, ginkgolinter: 0s, ineffassign: 0s"
level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildssa: failed to load package context: could not load export data: no export data for \"context\""
level=info msg="[runner] processing took 0s with stages: fixer: 0s, path_prefixer: 0s, skip_dirs: 0s, uniq_by_line: 0s, diff: 0s, max_from_linter: 0s, path_shortener: 0s, severity-rules-case-sensitive: 0s, path_prettifier: 0s, exclude-rules: 0s, nolint: 0s, max_same_issues: 0s, max_per_file_from_linter: 0s, cgo: 0s, autogenerated_exclude: 0s, identifier_marker: 0s, exclude: 0s, filename_unadjuster: 0s, skip_files: 0s, source_code: 0s, sort_results: 0s"
level=info msg="[runner] linters took 907.4508ms with stages: goanalysis_metalinter: 907.4508ms"
level=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: buildssa: failed to load package context: could not load export data: no export data for \"context\"\n\n"
level=info msg="Memory: 26 samples, avg is 64.8MB, max is 181.5MB"
level=info msg="Execution took 2.4968215s"

I tried solving this damn problem for 3 hours,i give up now.