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

Include GOROOT/bin to PATH when go wasn't found from PATH #713

Closed
hyangah opened this issue Sep 30, 2020 · 13 comments
Closed

Include GOROOT/bin to PATH when go wasn't found from PATH #713

hyangah opened this issue Sep 30, 2020 · 13 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Sep 30, 2020

The fix for #679 change to prepend GOROOT/bin to PATH or Path only if users explicitly configured to use go different from what's found from PATH. I forgot the case where go was not found from PATH, so the extension guessed and picked up a common default go installation directory. (C:\Go\bin or /usr/local/go/bin).

This is a regression and needs fix.

As a result, underlying tools such as gopls or delve that searches only PATH failed to locate the go binary. gopls crashes in this case.

For users who encountered this issue: You can try one of the followings for now:

Please try out https://github.com/golang/vscode-go/releases/tag/v0.17.2-rc.1
There is an instruction.

If it doesn't fix the issue, please update this issue.

Meanwhile, you can try one of the followings:

  • Option 1) downgrade to 0.17.0 for now (Extension view -> select 'Go' extension -> click the gear icon -> install another version -> select 0.17.0), or

  • Option 2) add "go.goroot": "/usr/local/go" temporarily until 0.17.1 is out, or

  • Option 3) add /usr/local/go/bin to your PATH and relaunch code for linux/mac users. C:\Go\bin to Path for windows users.

I recommend the Option 3


Edit: For people who wonder why VS Code reports a different PATH than what you see from the terminal:

When vscode launches for the first time, it initializes the environment like a login shell (~/.profile/~/.bash_profile/~/.zprofile ). When you try echo $PATH from the terminal, the shell environment may be set for interactive shell env (.bashrc, etc).

@hyangah hyangah added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 30, 2020
@hyangah hyangah added this to the v0.17.2 milestone Sep 30, 2020
@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/258316 mentions this issue: src/goInstallTools.ts: add GOROOT/bin to PATH when it wasn't found from PATH

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/258519 mentions this issue: [release] src/goInstallTools.ts: add GOROOT/bin to PATH when it wasn't found from PATH

gopherbot pushed a commit that referenced this issue Sep 30, 2020
…t found from PATH

The fix for #679 changed to prepend GOROOT/bin to PATH or Path
only if users explicitly configured to use go different from what's found from PATH.
I forgot the case where go was not found from PATH and the extension picked up
a common default go installation directory. (C:\Go\bin or /usr/local/go/bin).

This change rewrote the fix - rewrote getBinPath to return why it chose the
path as well. Then, we mutate the PATH env var if getBinPath picked
go with a reason other than it's in PATH (why === 'path').

Since getBinPath and getBinPathWithPreferredGopathGoroot are
used in many places, this CL introduces getBinPathWithExplanation and
getBinPath wraps it.

Updates #679
Fixes #713

Change-Id: Ie00612fcef2cf4c2a187a263da04b342182c030b
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/258316
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
(cherry picked from commit 9bf9d64)
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/258519
@hyangah
Copy link
Contributor Author

hyangah commented Sep 30, 2020

I created an RC with the fix here
https://github.com/golang/vscode-go/releases/tag/v0.17.2-rc.1

For users who were affected by this:
Can you please check if this fixes the issue for you? Thanks!

@saada
Copy link

saada commented Sep 30, 2020

Switching to the latest nightly extension above does not resolve the issue.

@dylan-bourque
Copy link

Same for me. I installed v1.17.2-rc.1 and the behavior is the same

@hyangah
Copy link
Contributor Author

hyangah commented Sep 30, 2020

@saada nightly doesn't have the fix yet.

@dylan-bourque Thanks! Can you please share 1) the full path of go binary you think it should use, 2) the PATH env var, and 3) the output of Go: Locate Go Tools command (Cmd+Shift+P or command palette)?

@saada
Copy link

saada commented Sep 30, 2020

downgrade to 0.17.0 worked for me!
Thanks @hyangah

@hyangah
Copy link
Contributor Author

hyangah commented Sep 30, 2020

@dylan-bourque Based on our chat in slack, the problem you encountered is different from this issue and preexisted before 0.17.1 release. The extension inherits all the environment vars set by vscode. So, if vscode does not pick up the right env var, I think you will need to file an issue to the vscode repo.

@saada thanks for the update. I'd appreciate it if you can help checking if the 0.17.2-rc.2 addresses the issue.

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/258557 mentions this issue: src/goEnvironmentStatus.ts: clear pre-installed terminal PATH mutation

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/258797 mentions this issue: [release] src/goEnvironmentStatus.ts: clear pre-installed terminal PATH mutation

gopherbot pushed a commit that referenced this issue Oct 1, 2020
…TH mutation

Changes to vscode.EnvironmentVariableCollection persist across
vscode sessions, so when we decide not to mutate PATH, we need to clear
the preexisting changes. The new function 'clearGoRuntimeBaseFromPATH'
reverses almost all of what addGoRuntimeBaseToPATH did on the persisted
state.

Manually tested by setting/unsetting "go.alternateTools".

Also, fixes the case where 'go.alternateTools' is set as an alternate
tool name rather than an absolute path - in that case, we search the
alternate tool from PATH. In this case, the reason shouldn't be 'path'.

Manually tested by setting
   "go.alternateTools": { "go": "mygo.sh" }

where "mygo.sh" is another binary that exists in PATH and shells out go.

In addition to this, this change fixes an exception thrown while
calling updateIntegratedTerminal when no 'go' executable is found from
the default PATH. In that case, getBinPathFromEnvVar returns null,
and path.dirname throws an error for non-string params.
This results in the failure of updating terminal's PATH change and
the users will not see the picked go from the terminal.
This is a bug preexisted before 0.17.1

Manually tested by launching code without go in PATH.

Updates #679
Fixes #713

Change-Id: I240694cb4425e81998299ab38097393a0f3faf46
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/258557
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
(cherry picked from commit 1b82f49)
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/258797
@hyangah
Copy link
Contributor Author

hyangah commented Oct 1, 2020

https://github.com/golang/vscode-go/releases/tag/v0.17.2 is released.
Please try it out! Thank you for your help with debugging.

@saada
Copy link

saada commented Oct 2, 2020

just tested v0.17.2 and it works now. Thank you!

@chamlokuge
Copy link

Referencing this #108003

I fixed the issue by installing the vscode using homebrew.
brew install --cask visual-studio-code.
open "/Applications/Visual Studio Code.app"

@golang golang locked and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants