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

VS Code unable to locate Go tools on my MacBook #108003

Closed
dylan-bourque opened this issue Oct 2, 2020 · 23 comments
Closed

VS Code unable to locate Go tools on my MacBook #108003

dylan-bourque opened this issue Oct 2, 2020 · 23 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@dylan-bourque
Copy link

  • VSCode Version:
    Version: 1.49.3
    Commit: 2af0510
    Date: 2020-10-02T17:54:06.165Z
    Electron: 9.2.1
    Chrome: 83.0.4103.122
    Node.js: 12.14.1
    V8: 8.3.110.13-electron.0

  • OS Version: Darwin x64 18.7.0

  • Go Extension Version: 0.17.2

Steps to Reproduce:

  1. Close all VS Code windows
  2. Launch VS Code by clicking on a pinned shortcut in the Dock

I get the error below:
image

While troubleshooting locally, I used the Go: Locate Configured Go Tools command from the Go Extension and it showed the following:

Checking configured tools....
GOBIN: undefined
toolsGopath: undefined
gopath: undefined
GOROOT: 
PATH: /usr/bin:/bin:/usr/sbin:/sbin

unable to locate "go" binary in GOROOT () or PATH (/usr/bin:/bin:/usr/sbin:/sbin)
unable to locate "go" binary in GOROOT () or PATH (/usr/bin:/bin:/usr/sbin:/sbin)

When I launch VS Code by running code from a terminal session the error message does not occur and the Go: Locate Configured Go Tools command correctly finds the Go tools.

Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /Users/dbourque/dev/golang
GOROOT: /usr/local/Cellar/go/1.15.2/libexec
PATH: [redacted]

   gocode: /Users/dbourque/dev/golang/bin/gocode installed
   gopkgs: /Users/dbourque/dev/golang/bin/gopkgs installed
   go-outline: /Users/dbourque/dev/golang/bin/go-outline installed
   go-symbols: /Users/dbourque/dev/golang/bin/go-symbols installed
   guru: /Users/dbourque/dev/golang/bin/guru installed
   gorename: /Users/dbourque/dev/golang/bin/gorename installed
   gotests: /Users/dbourque/dev/golang/bin/gotests installed
   gomodifytags: /Users/dbourque/dev/golang/bin/gomodifytags installed
   impl: /Users/dbourque/dev/golang/bin/impl installed
   fillstruct: /Users/dbourque/dev/golang/bin/fillstruct installed
   goplay: /Users/dbourque/dev/golang/bin/goplay installed
   godoctor: /Users/dbourque/dev/golang/bin/godoctor installed
   dlv: /Users/dbourque/dev/golang/bin/dlv installed
   gocode-gomod: /Users/dbourque/dev/golang/bin/gocode-gomod installed
   godef: /Users/dbourque/dev/golang/bin/godef installed
   goimports: /Users/dbourque/dev/golang/bin/goimports installed
   golangci-lint: /Users/dbourque/dev/golang/bin/golangci-lint installed
   gopls: /Users/dbourque/dev/golang/bin/gopls installed

go env
Workspace Folder (tryitout): /Users/dbourque/dev/tryitout
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/Users/dbourque/Library/Caches/go-build"
	GOENV="/Users/dbourque/Library/Application Support/go/env"
	GOEXE=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="darwin"
	GOINSECURE=""
	GOMODCACHE="/Users/dbourque/dev/golang/pkg/mod"
	GONOPROXY=""
	GONOSUMDB=""
	GOOS="darwin"
	GOPATH="/Users/dbourque/dev/golang"
	GOPRIVATE=""
	GOPROXY=""
	GOROOT="/usr/local/Cellar/go/1.15.2/libexec"
	GOSUMDB="off"
	GOTMPDIR=""
	GOTOOLDIR="/usr/local/Cellar/go/1.15.2/libexec/pkg/tool/darwin_amd64"
	GCCGO="gccgo"
	AR="ar"
	CC="clang"
	CXX="clang++"
	CGO_ENABLED="1"
	GOMOD="/Users/dbourque/dev/tryitout/go.mod"
	CGO_CFLAGS=""
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-g -O2"
	CGO_FFLAGS="-g -O2"
	CGO_LDFLAGS="-g -O2"
	PKG_CONFIG="/usr/local/bin/pkg-config"
	GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3t/4048hqr5459dw83ksmkqxn7r0000gn/T/go-build186798659=/tmp/go-build -gno-record-gcc-switches -fno-common"

Does this issue occur when all extensions are disabled?: No

This issue for the Go Extension generated the same error message but this fix for it does not correct the behavior for me.

@hyangah
Copy link

hyangah commented Oct 2, 2020

The PATH value is what the vscode gave to the extension. You can verify what PATH value vscode sees by

  1. launching vscode from dock (not from your terminal), and disabling the go extension,
  2. opening Developer: Toggle Developer Tools and
  3. querying process.env['PATH'] from the developer tool console.

@dylan-bourque What does it say?

FYI, this is different from golang/vscode-go#713.

Edit: I edited my msg a bit so vscode team can see the issue more clearly, not distracted by the go issue :-)

@jrieken jrieken added the info-needed Issue requires more information from poster label Oct 3, 2020
@CanRau
Copy link

CanRau commented Oct 3, 2020

This fixed it for me

  1. follow the instructions here to set GOPATH, GOROOT & PATH. NOTE: I didn't use the install.sh script!
  2. Close & open VSCode
  3. Disable & re-enable vscode-go plugin
  4. Hit Update on the notification popping up talking about a changed GOROOT

@jrieken jrieken self-assigned this Oct 5, 2020
@dylan-bourque
Copy link
Author

@hyangah process.env['PATH'] returns:

"/Users/dbourque/.pyenv/shims:/usr/local/opt/gnu-sed/libexec/gnubin:/Users/dbourque/.nvm/versions/node/v14.4.0/bin:/usr/local/opt/make/libexec/gnubin:/Users/dbourque/dev/golang/bin:/Users/dbourque/bin:/Users/dbourque/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/dbourque/Library/Python/2.7/bin"

I see here that /usr/local/bin is actually included and that is where my go binary is installed (by Brew). A bit strangely, $GOPATH is set to $HOME/dev/golang and $GOPATH/bin is added to $PATH in ~/.bashrc and that is included, even though one suggestion was that the problem is that the editor only reads .profile, .bash_profile and .zprofile on a Mac.

@CanRau I already have my environment configuration in ~/.bashrc like that link suggests.

As I've said, none of my "profile" files (~/.profile, ~/.bash_profile, ~/.zprofile, ~/.bashrc, ~/.zshrc) have changed at all. My environment (both login and interactive shells) is the same as it was 2 months ago when I was not seeing this error.

@jrieken
Copy link
Member

jrieken commented Oct 5, 2020

I am still not convinced that this is a VS Code issue

@dylan-bourque
Copy link
Author

From my standpoint, $GOROOT has never been set and $PATH has never included my Go installation based on just my .profile, .bash_profile and .zprofile environment. That environment configuration has been added in my .bashrc since I've had this machine (roughly a year) and this error message at startup is new (within the last few weeks). If I launch the editor from an open terminal (by running code) the error does not occur.

It appears that the Go extension is getting a system-default $PATH (only /usr/bin:/bin:/usr/sbin:/sbin) despite process.env['PATH'] containing additional directories (including /usr/local/bin which is where Go is installed).

@hyangah
Copy link

hyangah commented Oct 5, 2020

It's really strange that vscode-go sees a different process.env['PATH'] - the following is where the process.env['PATH'] is picked up in the go extension https://github.com/golang/vscode-go/blob/70f7a71e6bb85c987eefaca069185624f4c7168a/src/utils/pathUtils.ts#L20)

Note that the value is cached and it's initialized only once.

One possibility is that the process.env['PATH'] was changed after the go extension was initialized I think.

@dylan-bourque how about trying to downgrade 1) vscode (1.46 or 1.47?) and 2) vscode-go (0.15.2 maybe) and to narrow down the issue?

@dylan-bourque
Copy link
Author

I can try that later today or tomorrow.

@CanRau
Copy link

CanRau commented Oct 5, 2020

Strange, yeah interestingly the extension worked for me initially without any env/path changes only after the error wouldn't go away did I follow the instructions I linked before which luckily resolved my issue

@dylan-bourque
Copy link
Author

The only environment configuration I'm missing is explicitly setting $GOROOT. I've always relied on the fallback/default value of the Go install dir.

@hyangah
Copy link

hyangah commented Oct 5, 2020

@dylan-bourque you shouldn't need to set $GOROOT. Actually, that's not recommended.

@dylan-bourque
Copy link
Author

That was my understanding as well, but I noticed that it's included in the link that @CanRau posted.

@CanRau
Copy link

CanRau commented Oct 5, 2020

Yes I've set it as shown and it resolved all problems 🤷🏻‍♂️

Why's it not recommended? 🤔

@hyangah
Copy link

hyangah commented Oct 5, 2020

@CanRau Of course that's because the extension is also checking GOROOT/bin in addition to PATH etc. But what @dylan-bourque is getting at is about why the go extension isn't seeing the process.env['PATH'] it should see. I suspect a race between go extension's initialization and environment variable setup for extension host. Can we focus on the issue?

Re: why setting GOROOT is not recommended - if your GOROOT doesn't match what the go command thinks it should be, that can lead to other various issues. So, except a few cases where a different GOROOT is necessary, it's better to let the go command figure it out.

@hyangah
Copy link

hyangah commented Oct 8, 2020

FYI just encountered another issue that talks about PATH issue on Mac that started recently
#107169
#106537 (suggests a 1.49.x regression)

@jrieken
Copy link
Member

jrieken commented Oct 9, 2020

cc @joaomoreno

@joaomoreno
Copy link
Member

Is there any message in the DevTools like this?

Unable to resolve shell environment in a reasonable time

@dylan-bourque
Copy link
Author

I don't know if there was some specific change related to this, but I'm no longer seeing this behavior after updating VS Code to v1.50.0 and running the Go: Install/Update Tools command from the Go extension.

@jrieken jrieken closed this as completed Oct 15, 2020
@beamery-tomht
Copy link

beamery-tomht commented Oct 29, 2020

I'm getting this error, v1.50.1 hasn't fixed it. I'm seeing Unable to resolve shell environment in a reasonable time in my devtools.

@CanRau
Copy link

CanRau commented Oct 29, 2020

Same here, usually I have to restart VSCode, second start works as expected 🤷‍♂️

@beamery-tomht
Copy link

Running Developer: reload window fixed it for me. Seems they reduced the timeout for loading the environment from 10s to 3s.

@CanRau
Copy link

CanRau commented Oct 30, 2020

Uh good alternative, more work with multiple windows open tho 😅

@CanRau
Copy link

CanRau commented Nov 15, 2020

@beamery-tomht interestingly since yesterday quiting&re-opening VSCode won't work anymore, luckily your Developer: reload window trick works, even though I have to do it for every single window failing 😅 better than "not being able to work" I guess 🤷‍♂️

@beamery-tomht
Copy link

No worries @CanRau , I stole the idea from the depths of another github issue thread and have to do the same for all of my windows. Luckily not all of them need the full environment!

@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

7 participants
@joaomoreno @jrieken @hyangah @CanRau @dylan-bourque @beamery-tomht and others