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: error for 'go list' on a missing package is too terse with implicit '-mod=readonly' #41576

Closed
bcmills opened this issue Sep 23, 2020 · 4 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Sep 23, 2020

When -mod=readonly is set by default (see #40728), and go list fails to find a package named on the command line, it gives an error message of the form cannot find module providing package ….

However, with -mod=mod the command resolves the missing package and succeeds.

I think that behavior is a bit too subtle. The error message should explain why it didn't try to find a module providing the package, and/or suggest using go get to resolve that package.

CC @jayconrod @matloob

example.com$ go version
go version devel +150bd4ff Wed Sep 23 07:51:17 2020 +0000 linux/amd64

example.com$ go mod init example.com
go: creating new go.mod: module example.com

example.com$ go list golang.org/x/text
cannot find module providing package golang.org/x/text

example.com$ go list -mod=mod golang.org/x/text
go: finding module for package golang.org/x/text
go: downloading golang.org/x/text v0.3.3
go: found golang.org/x/text in golang.org/x/text v0.3.3
golang.org/x/text
@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker modules labels Sep 23, 2020
@bcmills bcmills added this to the Go1.16 milestone Sep 23, 2020
@bcmills
Copy link
Contributor Author

bcmills commented Sep 23, 2020

Marked as release-blocker for 1.16, because this situation is much more likely to occur given #40728.

@bcmills bcmills changed the title cmd/go: error for 'go list -mod=readonly' on a missing package is too terse cmd/go: error for 'go list' on a missing package is too terse with implicit '-mod=readonly' Sep 23, 2020
@bcmills bcmills assigned jayconrod and bcmills and unassigned jayconrod Sep 23, 2020
@gopherbot
Copy link

Change https://golang.org/cl/258298 mentions this issue: cmd/go: tweak ImportMissingError when module lookup is disabled

@gopherbot
Copy link

Change https://golang.org/cl/258717 mentions this issue: internal/lsp/testdata: remove diagnostic from percent package

gopherbot pushed a commit to golang/tools that referenced this issue Oct 1, 2020
The percent package has an invalid import path and a disallowed
character in a source file. In CL 258298, I am changing cmd/go to
diagnose invalid import paths during loading (instead of during
missing-import resolution), and as a result 'go list' will no longer
attempt to load or enumerate the source files for that package.

It is important that gopls and 'go list' not crash when attempting to
load a package with an invalid path, but gopls should not assume that
'go list' will produce anything more than an error for it.

For golang/go#37438
For golang/go#41576

Change-Id: I8af8896ea7108f1588e0085ddc1bf1b9ff55d5b9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258717
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
@mvdan
Copy link
Member

mvdan commented Oct 6, 2020

I just got surprised by this too. I had to think about it twice to remember that I should now do go mod tidy.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants