go: cmd/go: suppress errors for 'go get' of package paths that contain only tests
A Go module path is not necessarily a valid Go package path: for example, golang.org/x/tools
is a valid module path, but since there are no .go
files in the repo root it is not an importable package.
go get
in GOPATH
mode returns a non-zero exit code if that happens, but today in module mode we explicitly suppress that error:
https://github.com/golang/go/blob/dbd323bb880ff27fa9b4bdfebf3e5d4828b09678/src/cmd/go/internal/modget/get.go#L532-L536
On the other hand, if the user intends to pass a module path (rather than a package path), they can indicate that explicitly using the -m
flag.
Should we change the error-suppressing path to instead produce a non-zero exit code? We could still make the error explicit about the fact that the requested path is a module but not a package.
(CC @rsc @hyangah @myitcv @thepudds @jayconrod )
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 15 (11 by maintainers)
Here is another neat example, from a conversation with @lopezator. The root of
google.golang.org/genproto
contains.go
source files tagged with// +build ignore
. Since the directory contains a Go source file,go get
treats it as a package location; however, it cannot be built because the current configuration excludes that source file.The message is not
cannot find module providing
, sogo get
decides to report an error. (The behavior withgo1.11.4
is even worse: it reportsno install location for directory
, even whenGOBIN
is set!)One comment on the current implementation: it seems a repo root that only has a
*_test.go
file (but no other*.go
files) does trigger an error in 1.11.k8s.io/api
is an example repo that only has a test fileroundtrip_test.go
file in its repo root, which triggers an error if you dogo get k8s.io/api@master
:go get k8s.io/apimachinery@master
on the other hand works (where that repo root has no*.go
files).CC @bhcleek