Skip to content

cmd/go: "go get" can fail in a confusing way on the module path #44962

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

Closed
mvdan opened this issue Mar 12, 2021 · 6 comments
Closed

cmd/go: "go get" can fail in a confusing way on the module path #44962

mvdan opened this issue Mar 12, 2021 · 6 comments
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mvdan
Copy link
Member

mvdan commented Mar 12, 2021

I found this weird error while writing a reproducer for #44961. Using x/tools as an example:

$ go version
go version devel +cf59850466 Wed Mar 10 09:01:05 2021 +0000 linux/amd64
$ cd src/tools
$ git checkout -q 44abc2a71b321b77c0a579d8c5bf2704d648c9e0
$ go get -d golang.org/x/tools
go get golang.org/x/tools: unrecognized import path "golang.org/x": parse https://golang.org/x?go-get=1: no go-import meta tags ()
$ go get -d golang.org/x/tools@latest
go get: can't request version "latest" of the main module (golang.org/x/tools)
$ go get -d golang.org/x/tools@master
go get: can't request version "master" of the main module (golang.org/x/tools)

I'm not sure why the first go get gives that weird error message. I would expect the three commands to error in the same way.

@jayconrod jayconrod added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 12, 2021
@jayconrod jayconrod added this to the Go1.17 milestone Mar 12, 2021
@jayconrod
Copy link
Contributor

I think the can't request version "latest" of the main module messages are correct.

unrecognized import path "golang.org/x" is weird and confusing. I'm guessing that only comes up if the argument is the main module path? The go command would disqualify that when searching for packages, so it would be as if you typed go get golang.org/x, in which case that would be the correct message.

We should probably treat go get golang.org/x/tools just like go get golang.org/x/tools@upgrade. Technically, you might be looking for a package with the same path as the main module that actually is provided by another module, but it's unlikely.

@mvdan
Copy link
Member Author

mvdan commented Mar 12, 2021

Technically, you might be looking for a package with the same path as the main module that actually is provided by another module, but it's unlikely.

I think that falls under "noone should ever ever do this", so I don't think the error message should mention a parent module. I don't think we should even try to look for a parent module.

@jayconrod jayconrod added the okay-after-beta1 Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1 label May 17, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/331749 mentions this issue: cmd/go: do not go get main module inside its directory

@bcmills
Copy link
Contributor

bcmills commented Jul 30, 2021

go get -d golang.org/x/tools is requesting that we download the package-or-module golang.org/x/tools. There is no such package, but if golang.org/x/tools itself is the main module, then it is the latest version of itself and arguably the command should succeed without error.

That is, the lack of a corresponding package should cause the path to be interpreted as a module path, and then nothing should change because the main module is already (invariantly) the latest version of itself.

@bcmills
Copy link
Contributor

bcmills commented Jul 30, 2021

#37700 is closely related.

@dmitshur dmitshur removed the okay-after-beta1 Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1 label Aug 15, 2021
@dmitshur dmitshur modified the milestones: Go1.17, Backlog Aug 15, 2021
@iwdgo
Copy link
Contributor

iwdgo commented Sep 16, 2021

Issue was incidentally fixed by commit 109c13b64f815230af65af5c21e67cd7baa62a05 which merged dev.cmdgo development.

> gotip version
go version devel go1.18-ee91bb8319 Tue Sep 14 02:53:17 2021 +0000 windows/amd64
>gotip get  -d golang.org/x/tools
go: downloading golang.org/x/tools v0.1.5

It seems that issue can be closed for now.

@bcmills bcmills closed this as completed Sep 16, 2021
@golang golang locked and limited conversation to collaborators Sep 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants