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

x/tools/gopls: no packages returned: packages.Load error #42353

Closed
meakkineni opened this issue Nov 3, 2020 · 13 comments
Closed

x/tools/gopls: no packages returned: packages.Load error #42353

meakkineni opened this issue Nov 3, 2020 · 13 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@meakkineni
Copy link

What version of Go are you using (go version)?

$ go version go1.15.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mac/Library/Caches/go-build"
GOENV="/Users/mac/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mac/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mac/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"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mac/Documents/projects/myproject/test.com/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/mv/k0x9_cgs6mb7jqwstkwg1y9c0000gq/T/go-build174474178=/tmp/go-build -gno-record-gcc-switches -fno-common"
gopls trace Output
$ gopls -rpc.trace -v check main.go
gopls -rpc.trace -v check main.go
2020/11/02 22:37:16 Info:2020/11/02 22:37:16 go env for /Users/mac/Documents/projects/myproject/test.com
(root /Users/mac/Documents/projects/myproject/test.com)
(go version go version go1.15.3 darwin/amd64)
(valid build configuration = true)
(build flags: [])
GOPATH=/Users/mac/go
GOPRIVATE=
GOPROXY=https://proxy.golang.org,direct
GOMODCACHE=/Users/mac/go/pkg/mod
GONOPROXY=
GOSUMDB=sum.golang.org
GOCACHE=/Users/mac/Library/Caches/go-build
GONOSUMDB=
GOINSECURE=
GOROOT=/usr/local/go
GO111MODULE=on
GOMOD=/Users/mac/Documents/projects/myproject/test.com/go.mod
GOFLAGS=

2020/11/02 22:37:17 Info:2020/11/02 22:37:17 go/packages.Load
snapshot=0
directory=/Users/mac/Documents/projects/myproject/test.com
query=[builtin test.com/...]
packages=1
2020/11/02 22:37:17 Info:2020/11/02 22:37:17 go/packages.Load
snapshot=0
package_path="command-line-arguments"
files=[]
2020/11/02 22:37:17 Info:2020/11/02 22:37:17 go/packages.Load
snapshot=1
directory=/Users/mac/Documents/projects/myproject/test.com
query=[file=/Users/mac/Documents/projects/myproject/test.com/main.go]
packages=0
2020/11/02 22:37:17 Error:2020/11/02 22:37:17 reloadOrphanedFiles: failed to load: no packages returned: packages.Load error
query=[file:///Users/mac/Documents/projects/myproject/test.com/main.go]

What did you do?

I am trying to go to the definition of a function. For instance fmt.Println().
I use vim-go
I put the cursor under Println and try to go the definition and I get the below error
The same thing works when I change my definition server to 'guru'

Doesn't work either for user defined functions or for standard package functions

What did you expect to see?

Expected to see the definition of the function

What did you see instead?

no packages returned: packages.Load error

@toothrot toothrot changed the title Error on trying to find definition - "no packages returned: packages.Load error" x/tools/gopls: Error on trying to find definition - "no packages returned: packages.Load error" Nov 3, 2020
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Nov 3, 2020
@gopherbot gopherbot added this to the Unreleased milestone Nov 3, 2020
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 3, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/vscode-go Nov 4, 2020
@stamblerre
Copy link
Contributor

What is the output of go list -e -json -compiled ./... when you are in the /Users/mac/Documents/projects/myproject/test.com directory?

@stamblerre stamblerre added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 4, 2020
@meakkineni
Copy link
Author

Hi @stamblerre thanks for responding. This is what I see

$ go list -e -json -compiled ./...

go build internal/unsafeheader: loading compiled Go files from cache: reading srcfiles list: cache entry not found: open /Users/mac/Library/Caches/go-build/c0/c0e94ba9040544ec35c16499ee2905975dd7ec6b24e473a66a3aa2ec46e5f846-a: no such file or directory
go build unicode: loading compiled Go files from cache: reading srcfiles list: cache entry not found: open /Users/mac/Library/Caches/go-build/f1/f119670a773db65c0815a7827d762943142c014aeb48566d2b9eaa52f9903efb-a: no such file or directory
go build unicode/utf8: loading compiled Go files from cache: reading srcfiles list: cache entry not found: open /Users/mac/Library/Caches/go-build/95/9515ad0b3f4f5f63d1c4bbe8c238ad1345865fcc6118479bfddeec955a538a18-a: no such file or directory
go build internal/race: loading compiled Go files from cache: reading srcfiles list: cache entry not found: open /Users/mac/Library/Caches/go-build/97/97a4861b18817b8085b8685e54051446a4204c01b709430231b4257afa1f25cc-a: no such file or directory
go build math/bits: loading compiled Go files from cache: reading srcfiles list: cache entry not found: open /Users/mac/Library/Caches/go-build/1b/1b3caccfa06a6e29b2c6bdc528ffc5e7712931e997cb30d477c31e31f2a5dbee-a: no such file or directory
go build runtime/internal/sys: loading compiled Go files from cache: reading srcfiles list: cache entry not found: open /Users/mac/Library/Caches/go-build/29/29773ae629eba8ce238a7697425861a0be9c007b61408c0172f688f609ded2d0-a: no such file or directory
go build internal/cpu: loading compiled Go files from cache: reading srcfiles list: cache entry not found: open /Users/mac/Library/Caches/go-build/8c/8ca5bd8bd1572a5fecff05df9eeedf7d13b6c23a1320d5373a756df8d645e259-a: no such file or directory
go build runtime/internal/atomic: loading compiled Go files from cache: reading srcfiles list: cache entry not found: open /Users/mac/Library/Caches/go-build/51/51a0ab315d5778b2f56dbc221a7220e3d1e24940a9424be9f5e4bd07e321b94b-a: no such file or directory
go build sync/atomic: loading compiled Go files from cache: reading srcfiles list: cache entry not found: open /Users/mac/Library/Caches/go-build/f7/f76980501818889a818e399f49f4438edc3b14656a4616df4853c031cee3aa0d-a: no such file or directory
{
	"Dir": "/Users/mac/Documents/projects/myproject/test.com",
	"ImportPath": "test.com",
	"Name": "main",
	"Target": "/Users/mac/go/bin/test.com",
	"Root": "/Users/mac/Documents/projects/myproject/test.com",
	"Module": {
		"Path": "test.com",
		"Main": true,
		"Dir": "/Users/mac/Documents/projects/myproject/test.com",
		"GoMod": "/Users/mac/Documents/projects/myproject/test.com/go.mod",
		"GoVersion": "1.15"
	},
	"Match": [
		"./..."
	],
	"GoFiles": [
		"main.go"
	],
	"Imports": [
		"fmt"
	],
	"Deps": [
		"errors",
		"fmt",
		"internal/bytealg",
		"internal/cpu",
		"internal/fmtsort",
		"internal/oserror",
		"internal/poll",
		"internal/race",
		"internal/reflectlite",
		"internal/syscall/execenv",
		"internal/syscall/unix",
		"internal/testlog",
		"internal/unsafeheader",
		"io",
		"math",
		"math/bits",
		"os",
		"reflect",
		"runtime",
		"runtime/internal/atomic",
		"runtime/internal/math",
		"runtime/internal/sys",
		"sort",
		"strconv",
		"sync",
		"sync/atomic",
		"syscall",
		"time",
		"unicode",
		"unicode/utf8",
		"unsafe"
	]
}

@stamblerre
Copy link
Contributor

Thanks for sharing that output. My guess is that the issue is caused by the issues with the cache entries. Can you try running go clean -cache and then running the command again?

/cc @matloob @jayconrod @bcmills for further advice, especially since it seems like go/packages failed to pick up any packages with these error messages present

@stamblerre stamblerre changed the title x/tools/gopls: Error on trying to find definition - "no packages returned: packages.Load error" x/tools/gopls: no packages returned: packages.Load error Nov 4, 2020
@meakkineni
Copy link
Author

Yay!! I figured out what issue was

After I did go clean -cache and tried to build my app, it failed with the message

failed to initialize build cache at /Users/mac/Library/Caches/go-build: mkdir /Users/mac/Library/Caches/go-build/00: permission denied

After digging a bit I realized that go-build folder has root as its owner instead of $USER. I changed the owner to current user with the command sudo chown -R $USER ~/Library/Caches/go-build.

Now, everything works fine.

Thank you @stamblerre for your help!!

@uzair-ashraf
Copy link

Yay!! I figured out what issue was

After I did go clean -cache and tried to build my app, it failed with the message

failed to initialize build cache at /Users/mac/Library/Caches/go-build: mkdir /Users/mac/Library/Caches/go-build/00: permission denied

After digging a bit I realized that go-build folder has root as its owner instead of $USER. I changed the owner to current user with the command sudo chown -R $USER ~/Library/Caches/go-build.

Now, everything works fine.

Thank you @stamblerre for your help!!

If your go.mod file is emitting an error like below, @meakkineni 's solution works. Just adding here for SEO because it took me a minute to find this solution.

err: exit status 1: stderr: open /Users/user/Library/Caches/go-build/06/066240853ccf3ef2eec69ad02fc2409017c16ff6647a58580712d77e96956f4f-d: permission denied
: packages.Load error

@imiric
Copy link

imiric commented Nov 7, 2021

This error also happens if the file uses build tags, see #29202 (comment).

Trying the mentioned GOFLAGS workaround in Emacs with (setq-local process-environment '("GOFLAGS=-tags=<mytag>")) causes a different error: no views in session. 😕

@calebstewart
Copy link

Sorry to comment on a closed issue, but this is a huge deal for practically using gopls and all internet searches led me here. For anyone else on emacs that strolls through here, the solution @imiric gave didn't work for me. It appears to be replacing the entire environment with that one entry which breaks GOPATH. Therefore, I opted for setenv at a global scope which is then available to everything and only modifies/adds the one entry:

(setenv "GOFLAGS" "-tags=linux,windows")

This seems to let me interoperate between linux and windows tagged files. You could probably add darwin to the list if you need to work with MacOS as well, but I don't have that need at the moment. This doesn't seem to break anything else either. At least so far. 🤞

@vitaly-zdanevich
Copy link
Contributor

I have the same issue, go clean -cache did not help :(

@vitaly-zdanevich
Copy link
Contributor

~/Library/Caches/go-build

What is the path for Linux?

@computerphilosopher
Copy link

computerphilosopher commented Aug 19, 2022

@vitaly-zdanevich

The path of the go-build cache in the Linux is $HOME/.cache/go-build

but in my case, applying chown to this directory was not helped.

@dixler
Copy link

dixler commented Sep 1, 2022

hey, @computerphilosopher did you find a solution yet or are you living with it?

@computerphilosopher
Copy link

@dixler

In my case, I tried to navigate third-party module codes that are not installed yet. Running go install command at the project root solved my problem. But I have no idea about golang standard library.

@coderavels
Copy link

I was getting this error in lunarvim. My project was using vendoring, and running go clean -cache && go mod vendor resolved the issue for me.

@golang golang locked and limited conversation to collaborators Nov 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests