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: do not lookup *.go domains #38478

Closed
rsc opened this issue Apr 16, 2020 · 5 comments
Closed

cmd/go: do not lookup *.go domains #38478

rsc opened this issue Apr 16, 2020 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Apr 16, 2020

I accidentally ran "go get x.go foo" instead of "go run x.go foo".
The go command did:

go get x.go: unrecognized import path "x.go": https fetch: Get "https://x.go/?go-get=1": dial tcp: lookup x.go: no such host

It should probably instead reject the whole command if the first path ends in .go, to make this common mistake fail quicker and with a better error.

/cc @jayconrod @bcmills @matloob

@rsc rsc added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 16, 2020
@rsc rsc added this to the Go1.15 milestone Apr 16, 2020
@jayconrod
Copy link
Contributor

Related #32483 and #34653.

When we load packages for build commands, we check whether arguments ending with .go refer to existing files. If they don't, we treat them as package paths, since there are packages whose names end with .go.

We should check this in go get, too, so those packages can still be updated.

@rsc
Copy link
Contributor Author

rsc commented Apr 16, 2020

In my case the file did exist, so let's at least get this check into go get.
We should probably also reject any-no-slashes.go.

@anton-kuklin
Copy link
Contributor

anton-kuklin commented Apr 24, 2020

I will try to fix this bug.
Summarizing the task: we need to reject paths, which domain looks like *.go, but it's okay when the URL path ends with .go like github.com/nats-io/nats.go.
By all means, if I've got it wrong, please correct me. @rsc @jayconrod

@jayconrod
Copy link
Contributor

@justplesh It's a little simpler. For each argument, just consider the path (not counting any @version suffix). If the path ends with .go and either contains no slashes or refers to an existing file (not a directory), then report an error.

That should catch common mistakes without breaking real packages.

@gopherbot
Copy link

Change https://golang.org/cl/229938 mentions this issue: cmd: disable *.go domains lookup in go get command

xujianhai666 pushed a commit to xujianhai666/go-1 that referenced this issue May 21, 2020
Using 'go get x.go' instead of 'go build x.go' or some other
go command is a common mistake. By that mistake, a user gets
a misleading error message about unsuccessful `x.go` domain lookup.
This improvement handles such cases, by validating, whether the
argument hasn't specified version, has .go suffix, and either has
no slashes or such file locally exists. Handled both GOPATH
and GOMOD modes.

Fixes golang#38478

Change-Id: I583a4ef7f7ca8901deb07ebc811e2b3c0e828fa6
Reviewed-on: https://go-review.googlesource.com/c/go/+/229938
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Apr 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants