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: better error message for GOPATH set to GOROOT has no effect #70093

Closed
3052 opened this issue Oct 29, 2024 · 11 comments
Closed

cmd/go: better error message for GOPATH set to GOROOT has no effect #70093

3052 opened this issue Oct 29, 2024 · 11 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@3052
Copy link

3052 commented Oct 29, 2024

Go version

go version go1.23.2 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\spenny\AppData\Local\go-build
set GOENV=C:\Users\spenny\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\spenny\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\spenny\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\spenny\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\spenny\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.2
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\spenny\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\spenny\AppData\Local\Temp\go-build4205015363=/tmp/go-build -gno-record-gcc-switches

What did you do?

repost because previous issue was closed in error

go version

What did you see happen?

warning: GOPATH set to GOROOT (C:\Users\spenny\go) has no effect
go version go1.23.2 windows/amd64

What did you expect to see?

go version go1.23.2 windows/amd64

note I also tried to unset both values:

PS C:\Users\spenny\Desktop> go env -u GOROOT
warning: GOPATH set to GOROOT (C:\Users\spenny\go) has no effect
PS C:\Users\spenny\Desktop> go env -u GOPATH
warning: GOPATH set to GOROOT (C:\Users\spenny\go) has no effect
PS C:\Users\spenny\Desktop> go version
warning: GOPATH set to GOROOT (C:\Users\spenny\go) has no effect
go version go1.23.2 windows/amd64

also:

PS C:\Users\spenny\Desktop> go env -changed
warning: GOPATH set to GOROOT (C:\Users\spenny\go) has no effect

@ianlancetaylor
Copy link
Member

The default for GOPATH is the directory go in your home directory. You have installed Go such that that is also your GOROOT. If you want to use that value for GOROOT, you must explicitly set GOPATH to some other directory.

I'm going to close this because there is nothing to change in Go. If you want to discuss this, please use a forum; see https://go.dev/wiki/Questions. Thanks.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@3052
Copy link
Author

3052 commented Oct 29, 2024

@ianlancetaylor this comment is extremely salient:

#65656 (comment)

are you really not willing to admit that the current state is confusing?

@ianlancetaylor
Copy link
Member

I certainly agree that the current state is confusing.

What should we do about it?

If your goal with this issue is to get a better error message, I would encourage you to state that explicitly. This bug report doesn't say what the problem is and it doesn't make any suggestion as to what would be better. It is quite possible that these are very obvious to you. That does not mean that they are obvious to us. Thanks.

@3052
Copy link
Author

3052 commented Oct 29, 2024

Why would I do that? You've made it clear you're more interested in shutting down discussion instead of fostering it. If you mean what you say, reopen the issue and I will help however I can

@ianlancetaylor
Copy link
Member

You are absolutely correct about discussion: we've found that discussion on the issue tracker does not work. That's why we refer people to https://go.dev/wiki/Questions. The issue tracker is for bug reports. A bug report is a two-way street: we have to be able to understand what the problem is, and you have to take the time to explain the problem. It would be nice if we could just figure it out, but we can't. We are tiny team supporting millions of users. Help us out.

@3052
Copy link
Author

3052 commented Oct 29, 2024

the current summary by @tonymet does a great job in describing the current problem:

#65656 (comment)

in my opinion, nothing needs to be added to that. if someone need further detail I am happy to provide it. in short: some users are gonna get this warning and have no idea how to fix it, and the Go tool not only takes no action to help the problem, it doesn't even advise on an action. a simple "move your Go installation to another folder" or similar would go a long way

@xieyuschen
Copy link
Contributor

Go Wiki: Setting GOPATH has a note:

Note that GOPATH must not be the same path as your Go installation.

However, it doesn't say what will happen when they're the same so it's hard for users to refer this note because there is no link between warning warning: GOPATH set to GOROOT (%s) has no effect and this go wiki part.

We can consider to change 2 things:

compiler message:

The comment in L151 probably is better because user could easily know the behavior of GOPATH is not set by searching the GOPATH doc.

go/src/cmd/go/main.go

Lines 150 to 153 in 67f1314

// Diagnose common mistake: GOPATH==GOROOT.
// This setting is equivalent to not setting GOPATH at all,
// which is not what most people want when they do it.
if gopath := cfg.BuildContext.GOPATH; filepath.Clean(gopath) == filepath.Clean(cfg.GOROOT) {

User could reach the go wiki about GOPATH and find the default behavior of GOPATH, and they can easily come up with a solution by specifying GOPATH to another place.

If no GOPATH is set, it is assumed to be $HOME/go on Unix systems and %USERPROFILE%\go on Windows.

// main.go:
-		fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect\n", gopath)
+		fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect and it is equivalent to not setting GOPATH at all \n", gopath)

go wiki:

After changing the go error message, we can consider to add more details for Note that GOPATH must not be the same path as your Go installation.

I prefer to add 2 parts:

  1. Put the compiler warning message so it ensures the user could search it from search engine quickly.
  2. Add a sentence to guide users how to solve it if "the GOROOT and GOPATH are the same for some reasons".
// go wiki
Note that GOPATH must not be the same path as your Go installation.
+Consider to set GOPATH to another place which differs from GOROOT
+if you encountered a warning "GOPATH set to GOROOT...".

In this user case, users GOROOT and GOPATH are the same, so go compiler will try to use %USERPROFILE%\go to fallback. However, after fallback the GOPATH still equals to the GOROOT because the GOROOT is in the fallback place.
Instead of ending up with must not be the same in go doc, we can add some sentences so users could understand how to solve it.

HDYT? @ianlancetaylor @3052 If you think that's reasonable, I will send a CL in go. But need @ianlancetaylor help to amend go wiki because it requires the member role in golang organization and I'm not a member:(

@3052
Copy link
Author

3052 commented Oct 30, 2024

fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect and it is equivalent to not setting GOPATH at all \n", gopath)

I dont think this goes far enough. the root cause here is the user has put their Go installation in the wrong place, so the message should reflect that. if user is determined then the fix could be messing with go env, but I think in most cases the correct fix is just moving the go folder somewhere else.

@ianlancetaylor
Copy link
Member

I improved https://go.dev/wiki/InstallTroubleshooting, and sent https://go.dev/cl/623815 to change the error message to point to that wiki page.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/623815 mentions this issue: cmd/go: if GOPATH and GOROOT are the same, refer to wiki page

@cagedmantis cagedmantis added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 31, 2024
@cagedmantis cagedmantis added this to the Go1.24 milestone Oct 31, 2024
@seankhliao seankhliao changed the title GOPATH set to GOROOT has no effect cmd/go: better error message for GOPATH set to GOROOT has no effect Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants