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

Failed to find the "go" binary with direnv #2617

Closed
ciiqr opened this issue Jan 19, 2023 · 5 comments
Closed

Failed to find the "go" binary with direnv #2617

ciiqr opened this issue Jan 19, 2023 · 5 comments
Labels
FrozenDueToAge HelpWanted Issues that are not prioritized by the maintainers. Help is requested from community contributors. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ciiqr
Copy link

ciiqr commented Jan 19, 2023

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go1.18.9 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • v0.11.0
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.74.3
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.38.0-dev
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • not possible (due to the nature of the bug)

Share the Go related settings you have added/edited

N/A

Describe the bug

When using the vscode-go extension along with an extension like direnv that updates the PATH, I get the error:
Failed to find the "go" binary in either GOROOT() or PATH(...)

After some brief debugging I determined the issue to be with getBinPathWithPreferredGopathGorootWithExplanation which uses the cached envPath instead of the most up to date PATH from process.env.

I tested with this function updated to pull the path every time and this has resolved the issue. Code I used in my fork here for reference: master...ciiqr:vscode-go:fix/direnv-support

Steps to reproduce the behavior:

  1. install go/direnv extensions
  2. added an .envrc to my project with the contents: PATH_add /path/to/go/bin (assuming go isn't already in your path)
  3. ran command: direnv: Reset and reload environment to update the path
  4. clicked Restart on the popup direnv produces to reload all extensions
  5. go extension pops up with the Failed to find the "go" binary... error (with /path/to/go/bin clearly not in the path it shows)

Screenshots or recordings

@gopherbot gopherbot added this to the Untriaged milestone Jan 19, 2023
@findleyr
Copy link
Contributor

In general we do not update our environment after the extension host has started (doing so in full generality could be quite complicated).

I'm not sure we will be able to fix this. Do you find that other extensions do not have this problem?

@ciiqr
Copy link
Author

ciiqr commented Jan 19, 2023

this is the only extension I've had issues with (ie. rust-analyzer handles this just fine). The change shouldn't actually be that complicated. The direnv extension already reloads all extensions after updating process.env, it's just that vscode-go is storing the path from process.env once instead of reading it from process.env when it needs it, so it doesn't see the updated path. The change set I linked above was sufficient to fix the issue:
image

@findleyr
Copy link
Contributor

Aha, thanks for the additional info -- much appreciated. Also: I missed your patch above, thanks for highlighting it.

We'll investigate. If you want, feel free to send a PR with your fix -- it looks reasonable to me, though I'm not an expert on the extension.

@findleyr findleyr added NeedsFix The path to resolution is known, but the work has not been done. HelpWanted Issues that are not prioritized by the maintainers. Help is requested from community contributors. labels Jan 20, 2023
@findleyr findleyr modified the milestones: Untriaged, vscode-go/later Jan 20, 2023
@sun617
Copy link

sun617 commented Mar 27, 2023

I had the same issue

@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/494555 mentions this issue: don't cache environment PATH at the module level

@hyangah hyangah modified the milestones: vscode-go/later, v0.39.0 May 15, 2023
@golang golang locked and limited conversation to collaborators May 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge HelpWanted Issues that are not prioritized by the maintainers. Help is requested from community contributors. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants