cmd/run: error hint for "no required module provides package" is not helpful
#60,944 opened on Jun 22, 2023
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
In a directory that contains a go.mod, use go run to run a package that is not in the dependency graph with no version specified. Currently we tell you to go get tool. This probably isn't what you want (it will temporarily add the tool to your module, but it will be removed on the next go mod tidy). We should consider removing this hint.
$ go run golang.org/x/tools/cmd/stringer
no required module provides package golang.org/x/tools/cmd/stringer; to add it:
go get golang.org/x/tools/cmd/stringer
I created this issue to track the work mentioned on this comment from @rsc on https://github.com/golang/go/issues/48429#issuecomment-1601062050
@ConradIrwin, I think that error message change is not correct. If people are using "go run" then we shouldn't tell them to do something that is meant to be used with "go tool" but accidentally also makes "go run" work. Honestly I think the "to add it" note should probably be removed entirely. There are two possible ways to fix that error. The other is to add @version to the command line. Often that's what you want instead. We should stop presuming one solution.