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: go get should give a clearer error with GO111MODULE=off #66080

Open
ianlancetaylor opened this issue Mar 3, 2024 · 10 comments
Open

cmd/go: go get should give a clearer error with GO111MODULE=off #66080

ianlancetaylor opened this issue Mar 3, 2024 · 10 comments
Labels
BadErrorMessage Issues related compiler error messages that should be better. GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

Go version

6f5d774

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/iant/.cache/go-build'
GOENV='/home/iant/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/iant/gopath/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/iant/gopath'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org'
GOROOT='/home/iant/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/iant/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.23-6f5d77454e Sat Mar 2 14:01:52 2024 +0000'
GODEBUG=''
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/iant/go/src/go.mod'
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3030176309=/tmp/go-build -gno-record-gcc-switches'

What did you do?

> GO111MODULE=off go get -v go.wit.com/apps/test
go: modules disabled by GO111MODULE=off; see 'go help modules'
> go get -v go.wit.com/apps/test
go: module go.wit.com/apps/test: reading https://proxy.golang.org/go.wit.com/apps/test/@v/list: 404 Not Found
	server response: not found: go.wit.com/apps/test@latest: unrecognized import path "go.wit.com/apps/test": parse https://go.wit.com/apps/test?go-get=1: no go-import meta tags ()

What did you see happen?

See above.

What did you expect to see?

I expect to see a similar error message whether GO111MODULES is specified or not. The setting of that environment variable seems irrelevant for whether the Go package exists.

@mknyszek mknyszek added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. BadErrorMessage Issues related compiler error messages that should be better. labels Mar 4, 2024
@mknyszek mknyszek added this to the Backlog milestone Mar 4, 2024
@mknyszek
Copy link
Contributor

mknyszek commented Mar 4, 2024

CC @matloob @bcmills

@bcmills
Copy link
Contributor

bcmills commented Mar 4, 2024

I expect to see a similar error message whether [GO111MODULE] is specified or not. The setting of that environment variable seems irrelevant for whether the Go package exists.

As of Go 1.22, “go get is no longer supported outside of a module”. So the setting of the environment variable matters a lot: if it is set to off, go get doesn't work at all (and thus cannot report an error relating to a specific package).

So the difference in errors here is correct, but perhaps in the GO111MODULE=off case we could add a note specific to go get.

@bcmills bcmills added the GoCommand cmd/go label Mar 4, 2024
@bcmills bcmills changed the title cmd/go: bad error message with unknown module with GO111MODULES=off cmd/go: go get should give a clearer error with GO111MODULE=off Mar 4, 2024
@ianlancetaylor
Copy link
Contributor Author

Thanks. I now think that the general error should be improved to say something like go get requires module mode, which has been disabled by GO111MODULES=off. Since go get used to work in non-module mode, the error message isn't clear about what the problem is.

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 4, 2024
@bcmills
Copy link
Contributor

bcmills commented Mar 4, 2024

(@samthanawalla, want to take a look at this one?)

@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 4, 2024
@cuishuang
Copy link
Contributor

cuishuang commented Mar 27, 2024

Do you mind if I fix this problem?

The new output is similar to the image below.

image

@gopherbot
Copy link

Change https://go.dev/cl/574595 mentions this issue: cmd/go/internal/modload: go get provides clearer errors when GO111MODULE=off

@samthanawalla
Copy link
Contributor

samthanawalla commented Apr 1, 2024

I think to enable these more refined error messages, we need to work towards #40775
More specifically, modifying modload.Init to return errors instead of using base.Fatal in every case.

@cuishuang
Copy link
Contributor

I think to enable these more refined error messages, we need to work towards #40775 More specifically, modifying modload.Init to return errors instead of using base.Fatal in every case.

Thank you for your reply. I will try to research the ##40775

@matloob
Copy link
Contributor

matloob commented Apr 2, 2024

@cuishuang We're thinking about how best to address this. Please hold off on making further changes for now.

@cuishuang
Copy link
Contributor

@cuishuang We're thinking about how best to address this. Please hold off on making further changes for now.

Ok. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BadErrorMessage Issues related compiler error messages that should be better. GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants