Skip to content

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

Closed
@muirdm

Description

@muirdm

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

Activity

added
ToolsThis label describes issues relating to any tools in the x/tools repository.
goplsIssues related to the Go language server, gopls.
on Dec 2, 2020
added this to the Unreleased milestone on Dec 2, 2020
heschi

heschi commented on Dec 2, 2020

@heschi
Contributor

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

gopherbot commented on Dec 4, 2020

@gopherbot
Contributor

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

assigned and unassigned on Dec 7, 2020
added a commit that references this issue on Dec 23, 2020
b472908
locked and limited conversation to collaborators on Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stamblerre@gopherbot@muirdm@heschi

        Issue actions

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