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: panic related to go.mod #42949

Closed
muirdm opened this issue Dec 2, 2020 · 2 comments
Closed

x/tools/gopls: panic related to go.mod #42949

muirdm opened this issue Dec 2, 2020 · 2 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.
Milestone

Comments

@muirdm
Copy link

muirdm commented Dec 2, 2020

On master (7534955) I saw the below panic when I was messing around with my go.mod. I don't remember exactly what I was doing.

panic: runtime error: index out of range [0] with length 0

goroutine 2387481 [running]:
golang.org/x/tools/internal/imports.(*ModuleResolver).init(0xc07d75c000, 0x0, 0x0)
	/Users/muir/projects/tools/internal/imports/mod.go:91 +0x12bf
golang.org/x/tools/internal/imports.(*ModuleResolver).ClearForNewMod(0xc07d75c000)
	/Users/muir/projects/tools/internal/imports/mod.go:201 +0xb1
golang.org/x/tools/internal/lsp/cache.(*importsState).runProcessEnvFunc(0xc0008483c0, 0x1b17180, 0xc0552bdb30, 0xc0d2405ee0, 0xc07fce3980, 0x0, 0x0)
	/Users/muir/projects/tools/internal/lsp/cache/imports.go:77 +0x725
golang.org/x/tools/internal/lsp/cache.(*snapshot).RunProcessEnvFunc(0xc0d2405ee0, 0x1b17180, 0xc0552bdb30, 0xc07fce3980, 0xc0f0ce8000, 0x2)
	/Users/muir/projects/tools/internal/lsp/cache/view.go:315 +0x56
golang.org/x/tools/internal/lsp/source.AllImportsFixes(0x1b17180, 0xc0552bdb30, 0x1b28900, 0xc0d2405ee0, 0x1b1abc0, 0xc0f0ce8000, 0x1b28900, 0xc0d2405ee0, 0x1b1fbe0, 0xc0f0ce8000, ...)
	/Users/muir/projects/tools/internal/lsp/source/format.go:97 +0x34f
golang.org/x/tools/internal/lsp.(*Server).codeAction(0xc0001a2460, 0x1b170c0, 0xc037df8a00, 0xc0d5815780, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/muir/projects/tools/internal/lsp/code_action.go:84 +0x1c88
golang.org/x/tools/internal/lsp.(*Server).CodeAction(0xc0001a2460, 0x1b170c0, 0xc037df8a00, 0xc0d5815780, 0xc0d5815780, 0x0, 0x0, 0x0, 0x1b045a0)
	/Users/muir/projects/tools/internal/lsp/server_gen.go:12 +0x4d
golang.org/x/tools/internal/lsp/protocol.serverDispatch(0x1b170c0, 0xc037df8a00, 0x1b2b3e0, 0xc0001a2460, 0xc0552bd800, 0x1b17300, 0xc037df8940, 0x0, 0x1b04480, 0xc0f10836b0)
	/Users/muir/projects/tools/internal/lsp/protocol/tsserver.go:341 +0x20af
golang.org/x/tools/internal/lsp/protocol.ServerHandler.func1(0x1b170c0, 0xc037df8a00, 0xc0552bd800, 0x1b17300, 0xc037df8940, 0x40b64d043b8f, 0x1f83780)
	/Users/muir/projects/tools/internal/lsp/protocol/protocol.go:63 +0xc5
golang.org/x/tools/internal/lsp/lsprpc.handshaker.func1(0x1b170c0, 0xc037df8a00, 0xc0552bd800, 0x1b17300, 0xc037df8940, 0x0, 0x0)
	/Users/muir/projects/tools/internal/lsp/lsprpc/lsprpc.go:559 +0x452
golang.org/x/tools/internal/jsonrpc2.MustReplyHandler.func1(0x1b170c0, 0xc037df8a00, 0xc072622e40, 0x1b17300, 0xc037df8940, 0xc0c91eab60, 0x10426d6)
	/Users/muir/projects/tools/internal/jsonrpc2/handler.go:35 +0xcf
golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1.2(0xc0a7342900, 0xc139b555f0, 0xc0001fa690, 0x1b170c0, 0xc037df8a00, 0xc072622e40, 0x1b17300, 0xc037df8940)
	/Users/muir/projects/tools/internal/jsonrpc2/handler.go:103 +0x86
created by golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1
	/Users/muir/projects/tools/internal/jsonrpc2/handler.go:100 +0x173
@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 Dec 2, 2020
@gopherbot gopherbot added this to the Unreleased milestone Dec 2, 2020
@heschi
Copy link
Contributor

heschi commented Dec 2, 2020

It appears that the imports code got an environment with an empty GOPATH, which should be impossible unless you managed to completely break go env somehow. I don't think I'm going to be able to figure out the root cause, but we can certainly return an error here rather than crashing.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/275451 mentions this issue: internal/imports: prevent panic in imports GOMODCACHE logic

@heschi heschi assigned stamblerre and unassigned heschi Dec 7, 2020
marwan-at-work pushed a commit to marwan-at-work/tools that referenced this issue Dec 23, 2020
Fixes golang/go#42949

Change-Id: Icabfce85550cb6e69383ba50c2c675a5c730bec5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275451
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
@golang golang locked and limited conversation to collaborators Dec 7, 2021
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.
Projects
None yet
Development

No branches or pull requests

4 participants