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: diagnostics crash with empty go.mod #41005

Closed
josharian opened this issue Aug 22, 2020 · 2 comments
Closed

x/tools/gopls: diagnostics crash with empty go.mod #41005

josharian opened this issue Aug 22, 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

@josharian
Copy link
Contributor

Describe what you observed.

I ran touch go.mod in my terminal. I typed code go.mod. It opened the VSCode window in which I was already editing that directory.

Please attach the stack trace from the crash.

With some immediately preceding logs...

[Error - 1:10:22 PM] 2020/08/22 13:10:22 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -modfile=/var/folders/1t/n61cbvls5bl293bbb0zyypqw0000gn/T/go.4b5a0baa9a6293e3a96f0da74dbce1f5d5cf19d3.434481863.mod -- ./... builtin]: exit status 1: go: cannot determine module path for source directory /Users/josh/x/nu (outside GOPATH, module path must be specified)

Example usage:
	'go mod init example.com/m' to initialize a v0 or v1 module
	'go mod init example.com/m/v2' to initialize a v2 module

Run 'go help mod init' for more information.

	snapshot=0
	directory=/Users/josh/x/nu
	query=[./... builtin]
	packages=0

[Error - 1:10:22 PM] 2020/08/22 13:10:22 initial workspace load failed: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -modfile=/var/folders/1t/n61cbvls5bl293bbb0zyypqw0000gn/T/go.4b5a0baa9a6293e3a96f0da74dbce1f5d5cf19d3.434481863.mod -- ./... builtin]: exit status 1: go: cannot determine module path for source directory /Users/josh/x/nu (outside GOPATH, module path must be specified)

Example usage:
	'go mod init example.com/m' to initialize a v0 or v1 module
	'go mod init example.com/m/v2' to initialize a v2 module

Run 'go help mod init' for more information.
: packages.Load error

[Error - 1:10:22 PM] 2020/08/22 13:10:22 warning: diagnose go.mod: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -modfile=/var/folders/1t/n61cbvls5bl293bbb0zyypqw0000gn/T/go.4b5a0baa9a6293e3a96f0da74dbce1f5d5cf19d3.434481863.mod -- ./... builtin]: exit status 1: go: cannot determine module path for source directory /Users/josh/x/nu (outside GOPATH, module path must be specified)

Example usage:
	'go mod init example.com/m' to initialize a v0 or v1 module
	'go mod init example.com/m/v2' to initialize a v2 module

Run 'go help mod init' for more information.
: packages.Load error
	directory=/Users/josh/x/nu

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x1709d32]

goroutine 64 [running]:
golang.org/x/tools/internal/lsp/mod.ExtractGoCommandError(0x1aab740, 0xc00009ab70, 0x1abb7e0, 0xc000260900, 0x1aaf240, 0xc000032230, 0x1a97fc0, 0xc000292080, 0x0, 0x1012e79, ...)
	/Users/josh/pkg/mod/golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c/internal/lsp/mod/diagnostics.go:142 +0x7f2
golang.org/x/tools/internal/lsp.(*Server).handleFatalErrors(0xc000260080, 0x1aab740, 0xc00009ab70, 0x1abb7e0, 0xc000260900, 0x1a97fc0, 0xc000292080, 0x1a97fc0, 0xc000292080, 0xc000359560)
	/Users/josh/pkg/mod/golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c/internal/lsp/diagnostics.go:334 +0x1b0
golang.org/x/tools/internal/lsp.(*Server).diagnose(0xc000260080, 0x1aabd00, 0xc000248040, 0x1abb7e0, 0xc000260900, 0xc000062f00, 0x0, 0x0)
	/Users/josh/pkg/mod/golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c/internal/lsp/diagnostics.go:95 +0xb96
golang.org/x/tools/internal/lsp.(*Server).diagnoseDetached(0xc000260080, 0x1abb7e0, 0xc000260900)
	/Users/josh/pkg/mod/golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c/internal/lsp/diagnostics.go:33 +0xd4
golang.org/x/tools/internal/lsp.(*Server).addFolders.func2(0xc000260080, 0x1abb7e0, 0xc000260900, 0xc0004a3390)
	/Users/josh/pkg/mod/golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c/internal/lsp/general.go:222 +0x3f
created by golang.org/x/tools/internal/lsp.(*Server).addFolders
	/Users/josh/pkg/mod/golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c/internal/lsp/general.go:221 +0x8e5
[Error - 1:10:23 PM] Connection to server got closed. Server will not be restarted.
[Error - 1:10:23 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
	at Object.dispose (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:13824:25)
	at Object.dispose (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:10459:35)
	at LanguageClient.handleConnectionClosed (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:12694:42)
	at LanguageClient.handleConnectionClosed (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:70276:15)
	at closeHandler (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:12681:18)
	at CallbackList.invoke (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24070:39)
	at Emitter.fire (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24129:36)
	at closeHandler (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:13160:26)
	at CallbackList.invoke (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24070:39)
	at Emitter.fire (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24129:36)
	at StreamMessageReader.fireClose (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:28049:27)
	at Socket.<anonymous> (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:28089:46)
	at Socket.emit (events.js:208:15)
	at Pipe.<anonymous> (net.js:588:12)
[Error - 1:10:23 PM] Request textDocument/codeAction failed.
Error: Connection got disposed.
	at Object.dispose (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:13824:25)
	at Object.dispose (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:10459:35)
	at LanguageClient.handleConnectionClosed (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:12694:42)
	at LanguageClient.handleConnectionClosed (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:70276:15)
	at closeHandler (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:12681:18)
	at CallbackList.invoke (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24070:39)
	at Emitter.fire (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24129:36)
	at closeHandler (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:13160:26)
	at CallbackList.invoke (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24070:39)
	at Emitter.fire (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24129:36)
	at StreamMessageReader.fireClose (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:28049:27)
	at Socket.<anonymous> (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:28089:46)
	at Socket.emit (events.js:208:15)
	at Pipe.<anonymous> (net.js:588:12)
[Error - 1:10:23 PM] Request textDocument/documentLink failed.
Error: Connection got disposed.
	at Object.dispose (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:13824:25)
	at Object.dispose (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:10459:35)
	at LanguageClient.handleConnectionClosed (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:12694:42)
	at LanguageClient.handleConnectionClosed (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:70276:15)
	at closeHandler (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:12681:18)
	at CallbackList.invoke (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24070:39)
	at Emitter.fire (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24129:36)
	at closeHandler (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:13160:26)
	at CallbackList.invoke (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24070:39)
	at Emitter.fire (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:24129:36)
	at StreamMessageReader.fireClose (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:28049:27)
	at Socket.<anonymous> (/Users/josh/.vscode/extensions/golang.go-0.16.1/dist/goMain.js:28089:46)
	at Socket.emit (events.js:208:15)
	at Pipe.<anonymous> (net.js:588:12)
@suzmue
Copy link
Contributor

suzmue commented Aug 24, 2020

Thanks for filing this issue @josharian!

Looks like gopls is crashing when trying to add a diagnostic to the module declaration in a 'go.mod' file that doesn't have one

@suzmue suzmue changed the title gopls: automated issue report (crash) x/tools/gopls: diagnostics crash with empty go.mod Aug 24, 2020
@suzmue suzmue transferred this issue from golang/vscode-go Aug 24, 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 Aug 24, 2020
@gopherbot gopherbot added this to the Unreleased milestone Aug 24, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v.0.5.0 Aug 25, 2020
@gopherbot
Copy link

Change https://golang.org/cl/250657 mentions this issue: internal/lsp/mod: handle nil pointer exception for empty go.mod files

@golang golang locked and limited conversation to collaborators Aug 26, 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