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

cmd/go: can't inspect go env when $GOPATH/go.mod exists #46807

Open
zephyrtronium opened this issue Jun 17, 2021 · 3 comments
Open

cmd/go: can't inspect go env when $GOPATH/go.mod exists #46807

zephyrtronium opened this issue Jun 17, 2021 · 3 comments

Comments

@zephyrtronium
Copy link
Contributor

@zephyrtronium zephyrtronium commented Jun 17, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.3 windows/amd64

Does this issue reproduce with the latest release?

I haven't confirmed with go1.17beta1, but a quick scan through the history of cmd/go doesn't show any relevant changes, and I don't see any relevant issues on goissues.org.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\zephyr\AppData\Local\go-build
set GOENV=C:\Users\zephyr\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\go
set GOPRIVATE=
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 GOVCS=
set GOVERSION=go1.16.3
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\zephyr\AppData\Local\Temp
\go-build4050350410=/tmp/go-build -gno-record-gcc-switches

What did you do?

Create $GOPATH/go.mod, then execute the go tool:

PS C:\Users\zephyr\bug> $Env:GOENV="C:\Users\zephyr\bug\env"
PS C:\Users\zephyr\bug> go env -w GOPATH="C:\Users\zephyr\bug"
PS C:\Users\zephyr\bug> go mod init bug
go: creating new go.mod: module bug
go: to add module requirements and sums:
        go mod tidy
PS C:\Users\zephyr\bug> go env GOPATH
$GOPATH/go.mod exists but should not
PS C:\Users\zephyr\bug> go env
$GOPATH/go.mod exists but should not

A user encountered this issue after possibly VSCode or some other program set GOPATH in $GOENV. echo $GOPATH was empty, and ~/go/go.mod did not exist. They weren't able to inspect the go tool's value of GOPATH to diagnose the error because every go tool invocation (including go env -u GOPATH) gave only $GOPATH/go.mod exists but should not, and nothing suggested checking $GOENV or its default value.

What did you expect to see?

go env should print the environment regardless of whether $GOPATH/go.mod exists. It probably also should allow setting and unsetting variables.

Alternatively, the error message should print the value of GOPATH instead of only the variable name.

Another option would be to indicate that the user should check $GOENV if they think GOPATH should not contain go.mod.

What did you see instead?

$GOPATH/go.mod exists but should not

@golang golang deleted a comment Jun 17, 2021
@bcmills bcmills added this to the Backlog milestone Jun 17, 2021
@bcmills
Copy link
Member

@bcmills bcmills commented Jun 17, 2021

@danishprakash
Copy link

@danishprakash danishprakash commented Jul 11, 2021

@bcmills would like to work on this, is this open to new contributors?

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 3, 2021

Change https://golang.org/cl/339290 mentions this issue: modload: fix inspect go env when there is $GOPATH/go.mod exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants