Comments
rmilejcz
changed the title
sudden «context loading failed: no go files to analyze
sudden «context loading failed: no go files to analyze», v1.21.0
Oct 16, 2019
jirfag
changed the title
sudden «context loading failed: no go files to analyze», v1.21.0
Invalid error message «context loading failed: no go files to analyze» when can’t build project
Oct 17, 2019
jirfag
added
the
bug
Something isn’t working
label
Oct 17, 2019
This was referenced
Feb 13, 2020
meowsbits
added a commit
to meowsbits/core-geth
that referenced
this issue
May 5, 2020
jirfag
changed the title
Invalid error message «context loading failed: no go files to analyze» when can’t build project
context loading failed: no go files to analyze
May 18, 2020
jirfag
referenced
this issue
in golang/tools
May 18, 2020
Over time we have accumulated a disturbing number of ways to run the Go command, each of which supported slightly different features and workarounds. Combine all of them. This unavoidably introduces some changes in debug logging behavior; I think we should try to fix them incrementally and consistently. Updates golang/go#37368. Change-Id: I664ca8685bf247a226be3cb807789c2fcddf233d Reviewed-on: https://go-review.googlesource.com/c/tools/+/220737 Run-TryBot: Heschi Kreinick <heschi@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
jirfag
added a commit
that referenced
this issue
May 18, 2020
In case of timeouts of go/packages loading we could return such error. Relates: #825
jdobes
added a commit
to yungbender/vuln4shift-backend
that referenced
this issue
Mar 2, 2022
yungbender
pushed a commit
to yungbender/vuln4shift-backend
that referenced
this issue
Mar 3, 2022
yungbender
pushed a commit
to yungbender/vuln4shift-backend
that referenced
this issue
Mar 3, 2022
yungbender
pushed a commit
to yungbender/vuln4shift-backend
that referenced
this issue
Mar 3, 2022
yungbender
pushed a commit
to yungbender/vuln4shift-backend
that referenced
this issue
Mar 3, 2022
jdobes
added a commit
to RedHatInsights/vuln4shift-backend
that referenced
this issue
Mar 3, 2022
manno
added a commit
to manno/fleet-staging
that referenced
this issue
Jun 10, 2022
golangci-lint fails with a context error (maybe golangci/golangci-lint#825) Using the opportunity to bump the helm version, which was ~2 years old.
ldez
added
question
Further information is requested
and removed
bug
Something isn’t working
labels
Dec 26, 2022
Содержание
- no go files to analyze #78
- Comments
- level=error msg=»Running error: context loading failed: package github.com/sirupsen/logrus: no go files to analyze» #870
- Comments
- ERRO Running error: context loading failed: failed to load program with go/packages #395
- Comments
- Go linter running error, please make sure there’s no syntax error, then check for any config error #111
- Comments
- Footer
- Plugin doesn’t work in monorepo with multiple folders each with own go.mod #51
- Comments
no go files to analyze #78
GoLand 2021.1.3
Build #GO-211.7442.57, built on June 9, 2021
golangci-lint has version v1.41.1
The text was updated successfully, but these errors were encountered:
Hi @NSObjects , I’m afraid I didn’t understand your question, those 2 screenshots don’t seem related to the plugin? The plugin does not output anything, it does lint in editor.
And BTW the problem of the first screenshot is that the current running dir should be at
/Users/mac/Documents/Code/Go/mxtio/jsm_live
I am also receiving this error, even after the latest plugin updates (running v1.5.4). This is the error output in the GoLand log file (NOTE: I’ve removed my username from the path and replaced with ):
I am referencing a golangci-lint.yaml configuration file, however, removing that file as a configuration and replacing with the same selected linters also results in the same error.
I have tried the following:
- uninstall plugin
- reset IDE to ‘default settings’
- reinstall plugin
- multiple configuration options
Setup:
MacOSX BigSur v11.5.1
Goland v2021.2
Golangci-lint plugin v1.5.4
Golangci-lint installed through Homebrew v1.41.1
Источник
level=error msg=»Running error: context loading failed: package github.com/sirupsen/logrus: no go files to analyze» #870
I’m hitting this error when running golangci-lint v1.20.0 on github.com/projectcalico/libcalico-go
level=error msg=»Running error: context loading failed: package github.com/sirupsen/logrus: no go files to analyze»
$ go env
GO111MODULE=»on»
GOARCH=»amd64″
GOBIN=»»
GOCACHE=»/go-cache»
GOENV=»/home/user/.config/go/env»
GOEXE=»»
GOFLAGS=»-mod=vendor»
GOHOSTARCH=»amd64″
GOHOSTOS=»linux»
GONOPROXY=»»
GONOSUMDB=»»
GOOS=»linux»
GOPATH=»/go»
GOPRIVATE=»»
GOPROXY=»https://proxy.golang.org,direct»
GOROOT=»/usr/local/go»
GOSUMDB=»sum.golang.org»
GOTMPDIR=»»
GOTOOLDIR=»/usr/local/go/pkg/tool/linux_amd64″
GCCGO=»gccgo»
AR=»ar»
CC=»gcc»
CXX=»g++»
CGO_ENABLED=»0″
GOMOD=»/go/src/github.com/projectcalico/libcalico-go/go.mod»
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build253984656=/tmp/go-build -gno-record-gcc-switches»
The go.mod in libcalico-go replaces logrus with our fork of that package, but the problem persists if I remove that replace statement.
The text was updated successfully, but these errors were encountered:
Running go mod vendor before golangci-lint fixed this issue. But I’m not sure if golangci-lint should have considered GOFLAGS=»-mod=vendor» , so I’ll leave this open for further comments.
Источник
ERRO Running error: context loading failed: failed to load program with go/packages #395
- Version of golangci-lint: golangci-lint —version (or git commit if you don’t use binary distribution)
golangci-lint has version 1.14.0 built from 6c4d290 on 2019-02-11T06:59:20Z - Config file: cat .golangci.yml
- Go environment: go version && go env
- Verbose output of running: golangci-lint run -v
The text was updated successfully, but these errors were encountered:
hi, thank you for reporting!
github.com/. /pkg/buffer: no Go files in means that this package wasn’t loaded: most often this happens when dependencies weren’t installed. Is it dependency?
hi, thank you for reporting!
github.com/. /pkg/buffer: no Go files in means that this package wasn’t loaded: most often this happens when dependencies weren’t installed. Is it dependency?
yes, it’s dependency, and I probably know the reason. thx for your reply.
in my case (on jenkins), it solved my problem:
add in .golangci.yml
Feel I’ve just hit the same blocker. My program uses modules, so the vendor solution would not apply.
I’m first running go generate to get around any compile errors, then run linter. The build works locally but fails on travis:
may i know fix/workaround to resolve the issue ?
you need just to install all dependencies
Sorry to comment on a closed issue but how to make golangci-lint work with Go Modules?
I had to manually install all the dependencies ( go get -u github.com/. /. ), while they were already there with Modules ( go get ) and GO111MODULE was set to on .
Is there anything I’m missing here?
A possible solution, I guess, would be to disable Go Modules, go get , enable modules again, run golangci-lint . I’d like to avoid that path if there is a better solution though
Источник
Go linter running error, please make sure there’s no syntax error, then check for any config error #111
Constantly popping up: «Go linter running error, please make sure there’s no syntax error, then run ‘go mod tidy’ to make sure deps ok»
I’ve only installed the plugin — no custom config, running on defaults. Ofc running go mod tidy does not change a thing. Plugin does not work.
The text was updated successfully, but these errors were encountered:
It seems golangci-lint can not recognize my package name
it solved by run golangci-lint cache clean
golangci-lint cache clean does not change a thing.
The error keeps popping up.
@maciej-zh Can you share the error logs? You can find the log by click Help — Show Log in .
Then please search for go-linter , grab several error logs and paste here, thanks.
Obviously there are no syntax errors, all compiles, tests and works. And there are couple of .go files 😉
What’s more when I do golangci-lint run -v in the terminal it just works. Just the plugin does not work.
Thanks @maciej-zh ! Can you try run the debug command, that’s exactly what the plugin tried under the hood:
cd /Users/maciej/repos/maciej-scratchbook && export PATH=/opt/homebrew/Cellar/go/1.18.1/libexec/bin:/usr/bin:/bin:/usr/sbin:/sbin && export GOPATH= && ‘/opt/homebrew/Cellar/golangci-lint/1.46.2/bin/golangci-lint’ ‘run’ ‘—out-format’ ‘json’ ‘—allow-parallel-runners’ ‘-j’ ‘2’ ‘—issues-exit-code’ ‘1’ ‘—max-issues-per-linter’ ‘0’ ‘—max-same-issues’ ‘0’ ‘—no-config’ ‘—disable-all’ ‘-E’ ‘exportloopref,interfacer,staticcheck,dupl,govet,errorlint,funlen,gocritic,goconst,gocognit,ineffassign,bodyclose,gosec,maligned,unconvert,stylecheck,revive,whitespace,gosimple,goprintffuncname,gocyclo,prealloc’ ‘my-project/utils/pkg’
See if this works well in your terminal.
Hi @maciej-zh , quote you again in case you missed above message
My suspicion is that the plug-in can’t deal with project’s folder structure like that:
When I accidentally switched to another one with a classic structure of just go.mod and main.go in the root path it seems to be working fine.
Thanks @maciej-zh
In your case, yes, the plugin doesn’t work well in such a structure. Please consider using 2 Goland instances that open each project, to let golangci-lint correctly find the project root.
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
Plugin doesn’t work in monorepo with multiple folders each with own go.mod #51
If you have a folder, let’s say «project» with 2 sub-folders (project1, project2) each with its own go.mod, linter doesn’t work, as it’s trying to run golangci-lint in the root folder instead of in the project1/project2 folder according to the appropriate project.
This causes the following error:
The text was updated successfully, but these errors were encountered:
Hi @AdallomRoy , please consider using separate Goland instances to open those 2 sub-projects. As far as I know, Goland itself doesn’t work well in such case, unless you have checked ‘Index entire GOPATH’ option. The option is not recommended to use with go mod, it also blocked go mod integration within Goland.
Also, another workaround is select Project Root to 1 of the sub-project in plugin settings, while in this case the plugin will only work for the selected sub-project.
Hi @xxpxxxxp, it’s a repo with more than 90 projects, so I can’t really open each project by itself.
Fortunately, GoLand does support it quite well, and I have worked with them to improve performance for that use-case.
Also, I’m pretty sure that in one of the previous versions of the plugin it worked quite well.
I don’t think it’s complicated to add logic that searches for the deepest folder with a go.mod file and run golangci-lint from the folder instead of only running it from the project root.
Yeah, there was a refactoring to support #41 which will break this case. It would be easy to add an option to switch back the old way, if you aren’t using the exclude-rules in config. Will included in next release.
Источник
Apologies for not getting back to you sooner, but I’ve just added the appropriate Project GOPATH
and it still causes the plugin to fail. Strangely however, copying and pasting the output debug
command returns a working result?
2021-08-09 08:04:11,511 [ 13523] WARN - go-linter - Run error: level=error msg="Running error: context loading failed: no go files to analyze"
. Please make sure the project has no syntax error.
2021-08-09 08:04:11,516 [ 13528] WARN - go-linter - Debug command: cd /Users/sleyland/workspace/gocode/src/bitbucket.org/ffxblue/api-content && export PATH=/usr/local/Cellar/go/1.16.6/libexec/bin:/usr/bin:/bin:/usr/sbin:/sbin && export GOPATH=/Users/sleyland/workspace/gocode && '/usr/local/bin/golangci-lint' 'run' '--out-format' 'json' '--allow-parallel-runners' '-j' '3' '--max-issues-per-linter' '0' '--max-same-issues' '0' '-c' '/Users/sleyland/workspace/docker-go-linter/config/golangci-lint/full/.golangci.yaml' 'lib/rpc/api/content/asset/v2'
cd /Users/sleyland/workspace/gocode/src/bitbucket.org/ffxblue/api-content && export PATH=/usr/local/Cellar/go/1.16.6/libexec/bin:/usr/bin:/bin:/usr/s
bin:/sbin && export GOPATH=/Users/sleyland/workspace/gocode && '/usr/local/bin/golangci-lint' 'run' '--out-format' 'json' '--allow-parallel-runners' '-j' '3' '--max-issues-per-linter' '0' '--max-same-issues' '0' '-c' '/Users/sleyland/workspace/docker-go-linter/config/golangci-lint/full/.golangci.yaml' 'lib/rpc/api/content/asset/v2'
direnv: loading ~/workspace/gocode/src/bitbucket.org/ffxblue/api-content/.envrc
.env.override
direnv: export +HOST
WARN [runner] The linter 'scopelint' is deprecated (since v1.39.0) due to: The repository of the linter has been deprecated by the owner. Replaced by exportloopref.
{"Issues":[{"FromLinter":"wrapcheck","Text":"error returned from external package is unwrapped: sig: func bitbucket.org/ffxblue/api-content/vendor/google.golang.org/grpc/status.Error(c bitbucket.org/ffxblue/api-content/vendor/google.golang.org/grpc/codes.Code, msg string) error","Severity":"","SourceLines":["treturn nil, status.Error(codes.Unimplemented, "unimplemented")"],"Replacement":null,"Pos":{"Filename":"lib/rpc/api/content/asset/v2/asset.go","Offset":655,"Line":22,"Column":14},"ExpectNoLint":false,"ExpectedNoLintLinter":""}],"Report":{"Warnings":[{"Tag":"runner","Text":"The linter 'scopelint' is deprecated (since v1.39.0) due to: The repository of the linter has been deprecated by the owner. Replaced by exportloopref."}],"Linters":[{"Name":"govet","Enabled":true,"EnabledByDefault":true},{"Name":"bodyclose","Enabled":true},{"Name":"noctx","Enabled":true},{"Name":"errcheck","Enabled":true,"EnabledByDefault":true},{"Name":"golint"},{"Name":"rowserrcheck","Enabled":true},{"Name":"staticcheck","Enabled":true,"EnabledByDefault":true},{"Name":"unused","Enabled":true,"EnabledByDefault":true},{"Name":"gosimple","Enabled":true,"EnabledByDefault":true},{"Name":"stylecheck","Enabled":true},{"Name":"gosec","Enabled":true},{"Name":"structcheck","Enabled":true,"EnabledByDefault":true},{"Name":"varcheck","Enabled":true,"EnabledByDefault":true},{"Name":"interfacer"},{"Name":"unconvert","Enabled":true},{"Name":"ineffassign","Enabled":true,"EnabledByDefault":true},{"Name":"dupl"},{"Name":"goconst","Enabled":true},{"Name":"deadcode","Enabled":true,"EnabledByDefault":true},{"Name":"gocyclo","Enabled":true},{"Name":"cyclop"},{"Name":"gocognit","Enabled":true},{"Name":"typecheck","Enabled":true,"EnabledByDefault":true},{"Name":"asciicheck"},{"Name":"gofmt"},{"Name":"gofumpt","Enabled":true},{"Name":"goimports","Enabled":true},{"Name":"goheader"},{"Name":"gci"},{"Name":"maligned"},{"Name":"depguard","Enabled":true},{"Name":"misspell","Enabled":true},{"Name":"lll"},{"Name":"unparam","Enabled":true},{"Name":"dogsled","Enabled":true},{"Name":"nakedret","Enabled":true},{"Name":"prealloc","Enabled":true},{"Name":"scopelint","Enabled":true},{"Name":"gocritic","Enabled":true},{"Name":"gochecknoinits","Enabled":true},{"Name":"gochecknoglobals","Enabled":true},{"Name":"godox"},{"Name":"funlen"},{"Name":"whitespace"},{"Name":"wsl","Enabled":true},{"Name":"goprintffuncname"},{"Name":"gomnd","Enabled":true},{"Name":"goerr113"},{"Name":"gomodguard"},{"Name":"godot"},{"Name":"testpackage","Enabled":true},{"Name":"nestif","Enabled":true},{"Name":"exportloopref","Enabled":true},{"Name":"exhaustive"},{"Name":"sqlclosecheck","Enabled":true},{"Name":"nlreturn"},{"Name":"wrapcheck","Enabled":true},{"Name":"thelper","Enabled":true},{"Name":"tparallel","Enabled":true},{"Name":"exhaustivestruct"},{"Name":"errorlint","Enabled":true},{"Name":"paralleltest"},{"Name":"makezero","Enabled":true},{"Name":"forbidigo","Enabled":true},{"Name":"ifshort","Enabled":true},{"Name":"predeclared","Enabled":true},{"Name":"revive","Enabled":true},{"Name":"durationcheck","Enabled":true},{"Name":"wastedassign","Enabled":true},{"Name":"importas"},{"Name":"nilerr","Enabled":true},{"Name":"forcetypeassert","Enabled":true},{"Name":"gomoddirectives"},{"Name":"promlinter"},{"Name":"tagliatelle"},{"Name":"nolintlint","Enabled":true}]}}%
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
context loading failed: no go files to analyze
I have regularly run golangci-lint run
from the root of my directory without issue for the last several weeks. Today, after successfully running golangci-lint run
, I fixed all the reported issues and then ran the command in the same terminal but I got the output:
ERRO Running error: context loading failed: no go files to analyze
even though nothing seems to have changed. The project structure is basically 60 or so folders, each having a main.go
, a main_test.go
and two auto generated files which are ignored by golangci-lint
. If I specify a package it lints without issue e.g.:
golangci-lint run ActivityLog
runs the linter on that package without any error.
Version of golangci-lint
$ golangci-lint --version golangci-lint has version 1.21.0 built from 645e794 on 2019-10-15T18:15:04Z
Config file
$ cat .golangci.yml run: concurrency: 4 deadline: 2m issues-exit-code: 1 tests: true output: format: colored-line-number print-issued-lines: true print-linter-name: true linter-settings: errcheck: check-type-assertions: true check-blank: true govet: check-shadowing: true settings: printf: funcs: - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf golint: min-confidence: 0.8 gofmt: simplify: true goimports: local-prefixes: kalos-core gocyclo: min-complexity: 20 maligned: suggest-new: true goconst: min-len: 3 min-occurrences: 3 misspell: locale: US ignore-words: - supercalifragilisticexpialidocious lll: line-length: 120 tab-width: 2 unused: check-exported: false unparam: check-exported: false prealloc: simple: true range-loops: true for-loops: false gocritic: enabled-checks: - appendAssign - argOrder - assignOp - badCond - boolExprSimplify - builtinShadow - captLocal - caseOrder - commendOutCode - commentFormatting - commentedOutImport - defaultCaseOrder - deprecatedComment - docStub - dupArg - dupBranchBody - dupCase - dupSubExpr - elseif - emptyFallthrough - emptyStringTest - equalFold - exitAfterDefer - flagDeref - flagName - hexLiteral - hugeParam - ifElseChain - importShadow - indexAlloc - initClause - methodExprCall - nestingReduce - nilValReturn - octalLiteral - offBy1 - paramTypeCombine - ptrToRefParam - rangeExprCopy - rangeValCopy - regexpMust - singleCaseSwitch - sloppyLen - sloppyReassign - stringXbytes - switchTrue - typeAssertChain - typeSwitchVar - typeUnparen - underef - unlabelStmt - unlambda - unnecessaryBlock - unslice - valSwap - weakCond - wrapperFunc - yodaStyleExpr disabled-checks: - codegenComment - unnamedResult linters: enable: - bodyclose - megacheck - govet - errcheck - staticcheck - unused - gosimple - structcheck - varcheck - ineffassign - deadcode - typecheck - gosec - interfacer - unconvert - goconst - gocyclo - goimports - maligned - misspell - unparam - scopelint - gocritic - gochecknoinits disable: - dupl - lll - stylecheck
Go environment
$ go version && go env go version go1.13.1 darwin/amd64 GO111MODULE="on" GOARCH="amd64" GOBIN="/Users/robertmilejczak/Documents/Projects/bin" GOCACHE="/Users/robertmilejczak/Library/Caches/go-build" GOENV="/Users/robertmilejczak/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/robertmilejczak/Documents/Projects" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/Cellar/go/1.13.1/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.13.1/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/robertmilejczak/Documents/Projects/src/github.com/rmilejcz/kalos-core/go.mod" 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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kv/npdslxvd0ml09ntv_0rsmqcr0000gn/T/go-build078154239=/tmp/go-build -gno-record-gcc-switches -fno-common"
Verbose output of running
$ golangci-lint run -v INFO [config_reader] Config search paths: [./ /Users/robertmilejczak/Documents/Projects/src/github.com/rmilejcz/kalos-core/server /Users/robertmilejczak/Documents/Projects/src/github.com/rmilejcz/kalos-core /Users/robertmilejczak/Documents/Projects/src/github.com/rmilejcz /Users/robertmilejczak/Documents/Projects/src/github.com /Users/robertmilejczak/Documents/Projects/src /Users/robertmilejczak/Documents/Projects /Users/robertmilejczak/Documents /Users/robertmilejczak /Users /] INFO [config_reader] Used config file ../.golangci.yml INFO [lintersdb] Active 23 linters: [bodyclose deadcode errcheck gochecknoinits goconst gocritic gocyclo goimports gosec gosimple govet ineffassign interfacer maligned misspell scopelint staticcheck structcheck typecheck unconvert unparam unused varcheck] INFO [loader] Go packages loading at mode 575 (types_sizes|deps|imports|name|compiled_files|exports_file|files) took 1.436796726s ERRO Running error: context loading failed: no go files to analyze INFO Memory: 16 samples, avg is 68.9MB, max is 68.9MB INFO Execution took 1.451511334s
Disregard, for those getting a similar error message make sure you can build your project. I was able to figure out the issue by running
If possible, the error message context loading failed: no go files to analyze
should be improved, especially when specifying verbose ouput.
thank you, I think we need to fix error message
Hi, I’m having the same issue even in latest version 1.21.0, any ideas what could be the issue? Thanks.
The only advice I could give is to make sure your code is error free, run go build
or go test
to make sure that everything works as expected
This is tripping up our code formatting, as we’ve moved that to GolangCI Lint (running gofmt
and goimports
) rather than running those tools using locally installed versions. This is to ensure that a consistent toolset is used across all developers machines.
Goimports would normally clean up any import paths that don’t exist (e.g. from code that has been removed), however when running in GolangCI Lint, this gives the no go files to analyze
error instead
We had to downgrade to 1.17 to make it to work and about goimports we had to disable it and use it standalone without golangci lint. Maybe we are doing something wrong but at least we found a way. I think the linter doesn’t play nice with a multi go modules repository in our case, as we are using a mono repository with multiple go modules in it one per each service
For me it was connected to unupdated vendoring directory with enabled readonly mode.
In wtfutil/wtf#895 I used args: ./...
with golangci/golangci-lint-action@v0.2.0 to avoid this, though I don’t need to when running on my own machine.
Hi,
there at least two different cases:
- no
go.mod
on the root, it’s only in the subdirectory. I think it should be fixed by specifying a working directory because all built-in Go tooling doesn’t work with such cases. I’ve made golangci/golangci-lint-action#15 for our GitHub action. - timeout occurred during
go/packages
loading. The bug is ingo/packages
. We need help in fixing it and making a pull request to x/tools. The bug is in:
pkgs, err := packages.Load(conf, args...)
func goListDriver(cfg *Config, patterns ...string) (*driverResponse, error) {
func (state *golistState) createDriverResponse(words ...string) (*driverResponse, error) {
func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer, error) {
stdout, stderr, _, err := gocmdRunner.RunRaw(cfg.Context, inv)
— here we ignorefirendlyErr
which contains a context cancellation error. I guess the bug was introduced in this commit.
To reproduce it run in the repo ofgolangci-lint
:
golangci-lint cache clean && go clean -modcache -cache -i
golangci-lint run -v --timeout=5s
After merging #1154,
do you have examples of public repos where we can reproduce the problem with no go files
?
One way to reproduce this with golangci itself is to:
- Set
modules-download-mode: readonly
ingolangci.yml
- Remove a line from
go.sum
that does NOT have/go.mod
in the line (EG:github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
) - run golangci:
╰─ ./golangci-lint run ./... ERRO Running error: context loading failed: no go files to analyze
Seems to be packages.Load(conf, args...)
does not return an error even though the debug output with export GL_DEBUG=loader
set shows a debug line from packages
of:
DEBU [loader] 191.382563ms for GOROOT=/Users/ryancurrah/.go/current GOPATH= GO111MODULE= GOPROXY= PWD=/Users/ryancurrah/git/golangci-lint go [go list -mod=readonly -e -json -compiled=true -test=true -export=true -deps=true -find=false -mod=readonly -- ./...]
And that command from the debug log fails when I run it manually:
╰─ go list -mod=readonly -e -json -compiled=true -test=true -export=true -deps=true -find=false -mod=readonly -- ./... go: updates to go.sum needed, disabled by -mod=readonly
Why is packages.Load
not returning an error? I’ll try and figure this out
https://github.com/golangci/golangci-lint/blob/master/pkg/lint/load.go#L200
Ok after a bunch of time spent debugging the tools
package from golang I found the issue and created a Pull Request here: golang/tools#231.
If this fix is accepted packages.Load
will properly raise errors related to go.sum
issues instead of returning a empty slice of packages.
Then updating golang.org/x/tools
dependancy will solve this particular issue.
Note it may not solve all no go files to analyze
issues because the function invokeGo
selectively chooses which errors to raise based on stderr
text. Meaning not all errors are caught and this is done on purpose.
Just another thought. Whenever someone is having this issue they should run:
go list -mod=readonly -e -json -compiled=true -test=true -export=true -deps=true -find=false -- ./...
In their project to see if a error occurs. If one does; another pull request to the tools package to catch that error may be required.
If you don’t want to fix it, the command will at least tell you what’s really wrong.
That command is the same one the tools package uses.
We’re observing the same, but what’s not clear to me from the reports above: do others see this intermittently, or consistently? We do see it intermittently. We use the GitHub action, and rerunning sometimes fixes the issue. Running golangci-lint
locally never produced the error so far with our repo. If there’s more input I can provide, I’ll be happy to do so.
2020-07-03T14:38:06.8296454Z Running [/home/runner/golangci-lint-1.27.0-linux-amd64/golangci-lint run --out-format=github-actions -E gofmt] in [/home/runner/work/xxx] ...
2020-07-03T14:39:06.9584039Z level=error msg="Running error: context loading failed: no go files to analyze"
2020-07-03T14:39:06.9645099Z level=error msg="Timeout exceeded: try increasing it by passing --timeout option"
Edit: it turns out that there was nothing wrong with golangci-lint at all. Even the suggestion about the timeout was correct. It just really took a lot of time to lint our app for the first time (about two minutes). I was under the impression that this couldn’t be correct behaviour, as on my local machine linting would take at most 10 seconds. The answer lies in caching compiled go objects. Every Go GitHub actions 101 will explain that you should cache your dependencies, but don’t forget — especially for larger projects — to cache your build. Also, don’t be a smart-ass like me and just use golangci-lint action, it’s good.
Apologies.
The same here with golangci-lint 1.28.3. After deletion go.sum
and running go mod tidy
the problem was resolved for me and golangci-lint successfully started. Note, in my case the go.sum
is in the .gitignore
For us an upstream repo had a force tag push in it that was cached in go.sum.
To fix (on local machine):
rm go.sum go clean -modcache go mod tidy
then commit new go.sum
, push, and ci worked again
As @ryancurrah suggested
go list -mod=readonly -e -json -compiled=true -test=true -export=true -deps=true -find=false -- ./...
was very helpful and showed the error right away.
For us an upstream repo had a force tag push in it that was cached in go.sum.
To fix (on local machine):
rm go.sum go clean -modcache go mod tidythen commit new
go.sum
, push, and ci worked againAs @ryancurrah suggested
go list -mod=readonly -e -json -compiled=true -test=true -export=true -deps=true -find=false -- ./...
was very helpful and showed the error right away.
This fixed my problem.
I got this error today on OS X because ~/Library/Caches/go-build
was owned by root
. The go list
command mentioned by others above also tracked this problem down.