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

Empty environment variables passed to vs code are unset when debugging and running tests #2745

Closed
fedorareis opened this issue Apr 23, 2023 · 2 comments
Labels
FrozenDueToAge Infeasible Infeasible problem or feature request

Comments

@fedorareis
Copy link

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.

    • go version go1.20.2 darwin/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    golang.org/x/tools/gopls v0.11.0
    golang.org/x/tools/gopls@v0.11.0 h1:/nvKHdTtePQmrv9XN3gIUN9MOdUrKzO/dcqgbG6x8EY=
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp@v0.0.0-20221031165847-c99f073a8326 h1:QfTh0HpN6hlw6D3vu8DAwC8pBIwikq0AI1evdm+FksE=
    golang.org/x/exp/typeparams@v0.0.0-20221031165847-c99f073a8326 h1:fl8k2zg28yA23264d82M4dp+YlJ3ngDcpuB1bewkQi4=
    golang.org/x/mod@v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
    golang.org/x/sync@v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
    golang.org/x/sys@v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
    golang.org/x/text@v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
    golang.org/x/tools@v0.3.1-0.20221213193459-ca17b2c27ca8 h1:7/HkGkN/2ktghBCSRRgp31wAww4syfsW52tj7yirjWk=
    golang.org/x/vuln@v0.0.0-20221109205719-3af8368ee4fe h1:qptQiQwEpETwDiz85LKtChqif9xhVkAm8Nhxs0xnTww=
    honnef.co/go/tools@v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=
    mvdan.cc/gofumpt@v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
    go: go1.20.2

  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.

    • 1.77.3
    • 1.78.0-insider
  • Check your installed extensions to get the version of the VS Code Go extension

    • v0.38.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    gopath: /Users/kylereis/go
    GOROOT: /usr/local/Cellar/go/1.20.2/libexec
    PATH: /usr/local/opt/dirmngr/bin:/usr/local/sbin:/usr/local/bin:/Users/kylereis/go/bin:/usr/local/Cellar/go/1.20.2/libexec/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/share/dotnet:~/.dotnet/tools:/usr/local/git/bin:/usr/local/MacGPG2/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Library/TeX/texbin:/Applications/Wireshark.app/Contents/MacOS

    go: /usr/local/bin/go: go version go1.20.2 darwin/amd64

    gotests: /Users/kylereis/go/bin/gotests (version: v1.6.0 built with go: go1.20.2)
    gomodifytags: /Users/kylereis/go/bin/gomodifytags (version: v1.16.0 built with go: go1.20.2)
    impl: /Users/kylereis/go/bin/impl (version: v1.1.0 built with go: go1.20.2)
    goplay: /Users/kylereis/go/bin/goplay (version: v1.0.0 built with go: go1.20.2)
    dlv: /Users/kylereis/go/bin/dlv (version: unknown - )
    staticcheck: /Users/kylereis/go/bin/staticcheck (version: v0.4.3 built with go: go1.20.2)
    gopls: /Users/kylereis/go/bin/gopls (version: v0.11.0 built with go: go1.20.2)

go env
Workspace Folder (website): /Users/kylereis/Developer/website
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kylereis/Library/Caches/go-build"
GOENV="/Users/kylereis/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/kylereis/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/kylereis/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.20.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.20.2/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3v/20mqq59j7kg8nb5tc9jfltmc0000gp/T/go-build941490207=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

  • None

Describe the bug

When VS Code is launched with a set but empty env var, it as unset when doing things like running tests and running the debugger. There was an issue open in the Vscode repo (microsoft/vscode#174330) but it has been closed as fixed, but I still have the issue. so I'm rporting here in case there is an issue in the extension too.
The environment variables should be treated as empty when running tests and the debugger.

Steps to reproduce the behavior:

  1. Create a new go project
  2. Create a new go file ex.go with the following content
package main

import (
	"errors"
	"os"
)

func getVars(env string) (string, error) {
	val, set := os.LookupEnv(env)
	if !set {
		return "", errors.New("can't find variable:" + env)
	}
	return val, nil
}
  1. Create another new go file ex_test.go with the following content
package main

import "testing"

func TestGetVars(t *testing.T) {
	env := "BAR"
	_, err := getVars(env)
	if err != nil {
		t.Fatalf("%s not set", env)
	}

	env = "FOO"
	_, err = getVars(env)
	if err != nil {
		t.Fatalf("%s not set", env)
	}

}
  1. open the project using FOO="" BAR="test" code-insiders
  2. navigate to ex_test.go and run the test
  3. the test will fail on line 15 with the error "FOO not set"
@gopherbot gopherbot added this to the Untriaged milestone Apr 23, 2023
@findleyr
Copy link
Contributor

CC @hyangah

I can reproduce this bug. It seems like the sort of thing that could happen when conflating e.g. "" and undefined in javascript, but I read the code starting with getTestEnvVars, and didn't spot the bug. Might need help debugging.

@hyangah hyangah added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 15, 2023
@hyangah hyangah modified the milestones: Untriaged, vscode-go/later May 15, 2023
@hyangah
Copy link
Contributor

hyangah commented Sep 8, 2023

Looks like the root cause is somewhere deep in the stack microsoft/vscode#182560 (Chromium) which we cannot control unfortunately. FOO is lost way before the extension starts.

Closing since this is beyond the extension's control.

@hyangah hyangah closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2023
@hyangah hyangah added Infeasible Infeasible problem or feature request and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 8, 2023
@golang golang locked and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Infeasible Infeasible problem or feature request
Projects
None yet
Development

No branches or pull requests

4 participants