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

muirdm opened this issue Dec 2, 2020 · 2 comments

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

muirdm opened this issue Dec 2, 2020 · 2 comments


Copy link

@muirdm muirdm commented Dec 2, 2020

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

@heschi 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.

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.6.0 Dec 2, 2020
@stamblerre stamblerre added this to Needs Triage in vscode-go: gopls by default via automation Dec 2, 2020
@stamblerre stamblerre moved this from Needs Triage to Critical in vscode-go: gopls by default Dec 3, 2020
Copy link

@gopherbot gopherbot commented Dec 4, 2020

Change mentions this issue: internal/imports: prevent panic in imports GOMODCACHE logic

@stamblerre stamblerre moved this from Critical to In progress in vscode-go: gopls by default Dec 6, 2020
@heschi heschi assigned stamblerre and unassigned heschi Dec 7, 2020
vscode-go: gopls by default automation moved this from In progress to Done Dec 7, 2020
marwan-at-work added a commit to marwan-at-work/tools that referenced this issue Dec 23, 2020
Fixes golang/go#42949

Change-Id: Icabfce85550cb6e69383ba50c2c675a5c730bec5
Trust: Rebecca Stambler <>
Run-TryBot: Rebecca Stambler <>
gopls-CI: kokoro <>
TryBot-Result: Go Bot <>
Reviewed-by: Heschi Kreinick <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
No open projects
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants