Skip to content

x/tools/gopls: panic with invalid go.mod entry #35599

@muirdm

Description

@muirdm

I was playing around with my go.mod for personal reasons and had left it with an invalid "require":

module foo

go 1.13

require example.com/foo v1.2.3-456

gopls panics on startup after the "go list" error.

[Trace - 03:09:47 PM] Received notification 'window/logMessage'.
Params: {
  "message": "2019/11/14 15:09:47 : error loading packages: go [list -e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./...]: exit status 1: go: example.com/[email protected]: unrecognized import path \"example.com/foo\" (parse https://example.com/foo?go-get=1: no go-import meta tags ())\n",
  "type": 1
}
panic: runtime error: index out of range [0] with length 0

goroutine 52 [running]:
golang.org/x/tools/internal/lsp/cache.(*session).bestView(0xc0000eda20, 0xc0003a6630, 0x25, 0x0, 0x0)
	/Users/muir/projects/tools/internal/lsp/cache/session.go:226 +0x18f
golang.org/x/tools/internal/lsp/cache.(*session).DidOpen(0xc0000eda20, 0x19b32c0, 0xc00026d380, 0xc0003a6630, 0x25, 0x0, 0x4010000000000000, 0xc0003741e0, 0x51, 0x60, ...)
	/Users/muir/projects/tools/internal/lsp/cache/session.go:294 +0x2be
golang.org/x/tools/internal/lsp.(*Server).didOpen(0xc000265200, 0x19b32c0, 0xc00026d380, 0xc00034e2c0, 0x0, 0xc0003722c0)
	/Users/muir/projects/tools/internal/lsp/text_synchronization.go:30 +0x18c
golang.org/x/tools/internal/lsp.(*Server).DidOpen(0xc000265200, 0x19b32c0, 0xc00026d380, 0xc00034e2c0, 0xc00034e2c0, 0x0)
	/Users/muir/projects/tools/internal/lsp/server.go:135 +0x49
golang.org/x/tools/internal/lsp/protocol.serverHandler.Deliver(0x19cc840, 0xc000265200, 0x19b32c0, 0xc00026d380, 0xc000272bc0, 0xc00026d300, 0xc00020ec80)
	/Users/muir/projects/tools/internal/lsp/protocol/tsserver.go:111 +0x1b66
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc0000dcba0, 0xc000272bc0, 0xc000265260, 0x19b32c0, 0xc00026d380, 0x0, 0x0, 0xc000213730)
	/Users/muir/projects/tools/internal/jsonrpc2/jsonrpc2.go:370 +0x170
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
	/Users/muir/projects/tools/internal/jsonrpc2/jsonrpc2.go:354 +0x877

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions