Skip to content

x/tools/gopls: fail gracefully without a Go installation #41701

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

Closed
jherman opened this issue Sep 29, 2020 · 8 comments
Closed

x/tools/gopls: fail gracefully without a Go installation #41701

jherman opened this issue Sep 29, 2020 · 8 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

@jherman
Copy link

jherman commented Sep 29, 2020

gopls version: v0.5.0
gopls flags:

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: err: go command required, not found: exec: "go": executable file not found in %PATH%: stderr: 

goroutine 151 [running]:
golang.org/x/tools/internal/lsp/debug.PrintVersionInfo.func2()
	  info.go:58  0x253
golang.org/x/tools/internal/lsp/debug.section(0x17e0800, 0xc00060e330, 0x0, 0x16b4841, 0x7, 0xc00036cf28)
	  info.go:69  0x332
golang.org/x/tools/internal/lsp/debug.PrintVersionInfo(0x17f41e0, 0xc000535700, 0x17e0800, 0xc00060e330, 0x1, 0x0)
	  info.go:52  0x1b0
golang.org/x/tools/internal/lsp.(*Server).initialize(0xc0001add60, 0x17f41e0, 0xc000535700, 0xc000358000, 0x0, 0x0, 0x0)
	  general.go:87  0x58f
golang.org/x/tools/internal/lsp.(*Server).Initialize(0xc0001add60, 0x17f41e0, 0xc000535700, 0xc000358000, 0xc000358000, 0x0, 0x0)
	  server_gen.go:108  0x50
golang.org/x/tools/internal/lsp/protocol.serverDispatch(0x17f41e0, 0xc000535700, 0x1808560, 0xc0001add60, 0xc00034c360, 0x17f4420, 0xc000535680, 0x0, 0x17e1f80, 0xc000356000)
	  tsserver.go:235  0x4e2
golang.org/x/tools/internal/lsp/protocol.ServerHandler.func1(0x17f41e0, 0xc000535700, 0xc00034c360, 0x17f4420, 0xc000535680, 0x3ef1d19, 0x1c41740)
	  protocol.go:63  0xc7
golang.org/x/tools/internal/lsp/lsprpc.handshaker.func1(0x17f41e0, 0xc000535700, 0xc00034c360, 0x17f4420, 0xc000535680, 0x0, 0x0)
	  lsprpc.go:557  0x452
golang.org/x/tools/internal/jsonrpc2.MustReplyHandler.func1(0x17f41e0, 0xc000535700, 0xc00052ff40, 0x17f4420, 0xc000535680, 0x0, 0x0)
	  handler.go:35  0xda
golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1.2(0xc000039680, 0xc00054ac60, 0xc000530cb0, 0x17f41e0, 0xc000535700, 0xc00052ff40, 0x17f4420, 0xc000535680)
	  handler.go:103  0x8d
created by golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1
	  handler.go:100  0x179
[Error - 11:28:42 AM] 
@stamblerre stamblerre transferred this issue from golang/vscode-go Sep 29, 2020
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Sep 29, 2020
@stamblerre stamblerre changed the title gopls: automated issue report (crash) x/tools/gopls: fail gracefully without a Go installation Sep 29, 2020
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 29, 2020
@gopherbot gopherbot added this to the Unreleased milestone Sep 29, 2020
@stamblerre
Copy link
Contributor

Thanks for this report! Do you mind sharing the output of the Go: Locate Go Tools command (access it through the Command Palette -> Ctrl + Shift + P). Also, what are your VS Code settings?

@stamblerre
Copy link
Contributor

As a note to the person who fixes this -- we currently print gopls version and go version twice (once in initialize, once in initialized). We should remove the call in initialized and only print the gopls version there. We should then print the go version in the snapshot's WriteEnv function.

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Sep 29, 2020
@jherman
Copy link
Author

jherman commented Sep 29, 2020

@stamblerre, your requested information -

output of Go: Locate Configured Go Tools

Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: C:\Users\ME\go
GOROOT: c:\go
PATH: C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;c:\sysinternals\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\flutter\bin;C:\androidsdk\cmdline-tools\tools\bin;C:\jdk\bin;C:\Users\ME\AppData\Local\Microsoft\WindowsApps;C:\Users\ME\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\ME\AppData\Roaming\npm;C:\Users\ME\.dotnet\tools

   gocode: C:\Users\ME\go\bin\gocode.exe installed
   gopkgs: C:\Users\ME\go\bin\gopkgs.exe installed
   go-outline: C:\Users\ME\go\bin\go-outline.exe installed
   go-symbols: C:\Users\ME\go\bin\go-symbols.exe installed
   guru: C:\Users\ME\go\bin\guru.exe installed
   gorename: C:\Users\ME\go\bin\gorename.exe installed
   gotests: C:\Users\ME\go\bin\gotests.exe installed
   gomodifytags: C:\Users\ME\go\bin\gomodifytags.exe installed
   impl: C:\Users\ME\go\bin\impl.exe installed
   fillstruct: C:\Users\ME\go\bin\fillstruct.exe installed
   goplay: C:\Users\ME\go\bin\goplay.exe installed
   godoctor: C:\Users\ME\go\bin\godoctor.exe installed
   dlv: C:\Users\ME\go\bin\dlv.exe installed
   gocode-gomod: C:\Users\ME\go\bin\gocode-gomod.exe installed
   godef: C:\Users\ME\go\bin\godef.exe installed
   goreturns: C:\Users\ME\go\bin\goreturns.exe installed
   golint: C:\Users\ME\go\bin\golint.exe installed
   gopls: C:\Users\ME\go\bin\gopls.exe installed

go env
Workspace Folder (XXXX): g:\work\XXXX-build\repos\XXXX
	set GO111MODULE=on
	set GOARCH=amd64
	set GOBIN=
	set GOCACHE=C:\Users\ME\AppData\Local\go-build
	set GOENV=C:\Users\ME\AppData\Roaming\go\env
	set GOEXE=.exe
	set GOFLAGS=
	set GOHOSTARCH=amd64
	set GOHOSTOS=windows
	set GOINSECURE=
	set GOMODCACHE=C:\Users\ME\go\pkg\mod
	set GONOPROXY=bitbucket.org/XXXX/XXXX-packages
	set GONOSUMDB=bitbucket.org/XXXX/XXXX-packages
	set GOOS=windows
	set GOPATH=C:\Users\ME\go
	set GOPRIVATE=bitbucket.org/XXXX/XXXX-packages
	set GOPROXY=https://proxy.golang.org,direct
	set GOROOT=c:\go
	set GOSUMDB=sum.golang.org
	set GOTMPDIR=
	set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
	set GCCGO=gccgo
	set AR=ar
	set CC=gcc
	set CXX=g++
	set CGO_ENABLED=1
	set GOMOD=g:\work\XXXX-build\repos\XXXX\go.mod
	set CGO_CFLAGS=-g -O2
	set CGO_CPPFLAGS=
	set CGO_CXXFLAGS=-g -O2
	set CGO_FFLAGS=-g -O2
	set CGO_LDFLAGS=-g -O2
	set PKG_CONFIG=pkg-config
	set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ME\AppData\Local\Temp\go-build345760914=/tmp/go-build -gno-record-gcc-switches

VS Code Settings:

{
    "team.showWelcomeMessage": false,
    "sync.gist": "d2ed56573a6a4c6ee8ee4e7b8bfca48e",
    "git.enableSmartCommit": true,
    "git.confirmSync": false,
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "workbench.iconTheme": "vscode-icons",
    "git.postCommitCommand": "push",
    "vsicons.dontShowNewVersionMessage": true,
    "vs-kubernetes": {
        "vs-kubernetes.minikube-path": "C:\\Users\\ME\\.vs-kubernetes\\tools\\minikube\\windows-amd64\\minikube.exe",
        "vs-kubernetes.helm-path": "C:\\Users\\ME\\.vs-kubernetes\\tools\\helm\\windows-amd64\\helm.exe",
        "vs-kubernetes.draft-path": "C:\\Users\\ME\\.vs-kubernetes\\tools\\draft\\windows-amd64\\draft.exe",
        "vs-kubernetes.kubectl-path": "C:\\Users\\ME\\.vs-kubernetes\\tools\\kubectl\\kubectl.exe",
        "vs-kubernetes.minikube-path.windows": "C:\\Users\\ME\\.vs-kubernetes\\tools\\minikube\\windows-amd64\\minikube.exe"
    },
    "git.autofetch": true,
    "window.zoomLevel": 0,
    "editor.tabCompletion": "on",
    "workbench.colorTheme": "Dracula",
    "editor.renameOnType": true,
    "go.useLanguageServer": true,
    "go.delveConfig": {
        "dlvLoadConfig": {
            "followPointers": true,
            "maxVariableRecurse": 1,
            "maxStringLen": 99999,
            "maxArrayValues": 64,
            "maxStructFields": -1
        },
        "apiVersion": 2,
        "showGlobalVariables": true
    },
    "workbench.editor.scrollToSwitchTabs": true,
    "editor.fontFamily": "'Envy Code R VS', 'JetBrains Mono', FiraFlott, Consolas, 'Courier New', monospace",
    "editor.find.addExtraSpaceOnTop": false,
    "workbench.list.smoothScrolling": true,
    "explorer.confirmDelete": false,
    "editor.cursorSmoothCaretAnimation": true,
    "editor.cursorBlinking": "expand",
    "terminal.integrated.cursorBlinking": true,
    "workbench.colorCustomizations": {
        "editor.selectionBackground": "#721616",
        "editor.selectionHighlightBackground": "#721616",
        "editor.findMatchBackground": "#00cc44a8", //Current SEARCH MATCH
        "editor.findMatchHighlightBackground": "#ff7b00a1", //Other SEARCH MATCHES
        "[Dracula]": {
            // "editorCursor.background": "#ffa600",
            "editorCursor.foreground": "#ff00dd",
        }
    },
    "editor.cursorWidth": 3,
    "powershell.powerShellDefaultVersion": "Windows PowerShell (x86)",
    "yaml.schemas": {
        "https://bitbucket.org/atlassianlabs/atlascode/raw/main/resources/schemas/pipelines-schema.json": "/bitbucket*"
    },
    "[json]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[yaml]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[typescript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },
    "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "[javascript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },
    "[html]": {
        "editor.defaultFormatter": "vscode.html-language-features"
    },
    "[dart]": {
        "editor.formatOnSave": true,
        "editor.formatOnType": true,
        "editor.rulers": [
            80
        ],
        "editor.selectionHighlight": false,
        "editor.suggest.snippetsPreventQuickSuggestions": false,
        "editor.suggestSelection": "first",
        "editor.tabCompletion": "onlySnippets",
        "editor.wordBasedSuggestions": false
    },
    "[scss]": {
        "editor.defaultFormatter": "michelemelluso.code-beautifier"
    },
    "search.useIgnoreFiles": false,
    "editor.formatOnSave": true,
}

@hyangah
Copy link
Contributor

hyangah commented Sep 29, 2020

@jherman It looks like C:\Go\bin is not in PATH.

This looks like a new problem triggered by VS Code Go 0.17.1 which no longer mutates PATH env vars unless user set go.goroot or go.alternateTools.
(golang/vscode-go#679) But we didn't consider the case where user's PATH doesn't have the Go installation location but the extension found one from a guessed location.

While we are fixing the issues in gopls and the extension, you can try one of the followings

  1. Downgrade vscode-go to 0.17.0
  2. "go.goroot": "C:\Go"
  3. Correct PATH to include C:\Go\bin

I recommend option 3, but not sure what's the easiest way to configure PATH env vars on windows. set PATH c:\Go\bin;%PATH% or 'Advanced System Settings -> Environment Variables' ...

@jherman
Copy link
Author

jherman commented Sep 29, 2020

@hyangah Options 3 fixed the issue. Thank you.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/258312 mentions this issue: internal/lsp: print the go version only once the view is created

@subsr97
Copy link

subsr97 commented Sep 30, 2020

I'm on Ubuntu.
My $PATH already had /usr/local/go/bin/.
Adding "go.goroot": "/usr/local/go" fixed the issue for me.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/258517 mentions this issue: [gopls-release-branch.0.5] internal/lsp: print the go version only once the view is created

gopherbot pushed a commit to golang/tools that referenced this issue Sep 30, 2020
…ce the view is created

Printing the Go version without the session's go command runner means
that we may not find the right Go version. Also, panicking when we
cannot find a go command is not useful to the user--show the error as a
view initialization error instead.

Fixes golang/go#41701

Change-Id: I0e0753da9795b1c78331db1faecd27c2bfcee9b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258312
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: Robert Findley <rfindley@google.com>
(cherry picked from commit 66e72d0)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258517
@golang golang locked and limited conversation to collaborators Sep 30, 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

5 participants