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: "no required module provides package" is confusing for paths under the current module #44961

Open
mvdan opened this issue Mar 12, 2021 · 7 comments
Labels
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

Using https://pkg.go.dev/golang.org/x/tools/cmd/benchcmp as an example:

$ go version
go version devel +cf59850466 Wed Mar 10 09:01:05 2021 +0000 linux/amd64
$ cd tools
$ git checkout -q 44abc2a71b321b77c0a579d8c5bf2704d648c9e0
$ cd cmd/benchcmp
$ sed -i 's@benchmark/parse@missing/package@g' *.go
$ go build
benchcmp.go:15:2: no required module provides package golang.org/x/tools/missing/package; to add it:
	go get golang.org/x/tools/missing/package
$ go get golang.org/x/tools/missing/package
go get golang.org/x/tools/missing/package: no matching versions for query "upgrade"

What I do here is add an import to a missing package that could be part of the current main module. The example I use is perhaps silly, but it's somewhat common to end up in this situation. For example:

  • Rebasing or applying an old patch that imports a package which is now moved or deleted
  • Writing an import manually and making a typo

I get why the errors are technically correct. When I run go build, the go tool doesn't know if there happens to be a module with path golang.org/x/tools/missing or golang.org/x/tools/missing/package, which could possibly contain the package needed. And, when I run the go get, it finds no such module, and the main module can't be upgraded to contain such a package.

First, an assumption: nested Go modules are very rare, and should not be encouraged. So I don't think that we should be optimizing the error messages for that use case.

Now, some suggestions from the user's point of view, for this scenario:

  1. The go build error shouldn't suggest go get. It's very unlikely that it will fix the problem. If the user really has nested modules that would be fixed with a go get, I imagine they know what they're doing and can figure out what to do.

For example, here's a suggestion:

$ go build
benchcmp.go:15:2: package golang.org/x/tools/missing/package does not exist in the main module
  1. The go get error is confusing. For example, see what happens if I try to upgrade the main module:
$ go get -d golang.org/x/tools@latest
go get: can't request version "latest" of the main module (golang.org/x/tools)

Now, compare that with package paths:

$ go get -d golang.org/x/tools/foo/bar
go get golang.org/x/tools/foo/bar: no matching versions for query "upgrade"
$ go get -d golang.org/x/tools/foo/bar@latest
go get golang.org/x/tools/foo/bar@latest: no matching versions for query "latest"

If no nested module is found, I think it should just show the can't request version error, just like go get -d golang.org/x/tools@latest.

@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

While the error message is technically correct (the package could be in another module with a longer path, and go get might add the correct requirement), it's far more likely that the package just doesn't exist. I agree that your proposed go build error message is better. The go get messages seem like they could be improved, too.

@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

Change https://golang.org/cl/324470 mentions this issue: cmd/go: improve "invalid version" error messages

@bcmills
Copy link
Contributor

bcmills commented Jun 7, 2021

Compare #33568.

@jayconrod jayconrod modified the milestones: Go1.17, Go1.18 Jul 29, 2021
@ianlancetaylor
Copy link
Contributor

This is in the Go1.18 milestone. Is it likely to happen for 1.18? Thanks.

@ianlancetaylor
Copy link
Contributor

@bcmills This is in the 1.18 milestone; time to move to 1.19? Thanks.

@bcmills bcmills modified the milestones: Go1.18, Backlog Jan 28, 2022
@ghost

This comment was marked as duplicate.

@iwdgo
Copy link
Contributor

iwdgo commented May 14, 2022

Issue seems solved. It is difficult to locate which commit but on go1.18 with the case filed, the message is more explicit. The reference to go get is replaced by the import causing the error (missing/path in this case).

GOPATH\golang\x\tools\cmd\benchcmp>go version
go version go1.18.1 windows/amd64

GOPATH\golang\x\tools\cmd\benchcmp>set GO111MODULE
GO111MODULE=off

GOPATH\golang\x\tools\cmd\benchcmp>go build
code in directory C:\Users\Costa\Documents\Google\golang\x\tools\cmd\benchcmp expects import "golang.org/x/tools/cmd
/benchcmp"
benchcmp.go:10:2: cannot find package "missing/path" in any of:
        C:\Program Files\Go\src\missing\path (from $GOROOT)
        C:\Users\Costa\Documents\Google\src\missing\path (from $GOPATH)

GOPATH\golang\x\tools\cmd\benchcmp>set GO111MODULE=

GOPATH\Google\golang\x\tools\cmd\benchcmp>go build
benchcmp.go:10:2: cannot find package "." in:
        C:\Users\Costa\Documents\Google\golang\x\tools\vendor\missing\path

GOPATH\golang\x\tools\cmd\benchcmp>

@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 Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

7 participants