Go: cmd/go: clarify error message for 'go get -u' without arguments in a module root that is not a package

Created on 5 Mar 2020  ·  6Comments  ·  Source: golang/go

What version of Go are you using (go version)?

go version go1.14 darwin/amd64

What did you do?

I'm working on a project that has no Go package in the root directory of the module. Running go get -u in the root results in

go get .: path $pkgpath is not a package in module rooted at $pkgpath

go help get states both

If an argument names a module but not a package (because there is no
Go source code in the module's root directory), then the install step
is skipped for that argument, instead of causing a build failure.
For example 'go get golang.org/x/perf' succeeds even though there
is no code corresponding to that import path.

and

With no package arguments, 'go get' applies to Go package in the
current directory, if any. In particular, 'go get -u' and
'go get -u=patch' update all the dependencies of that package.
With no package arguments and also without -u, 'go get' is not much more
than 'go install', and 'go get -d' not much more than 'go list'.

This seems to imply, to me, that running go get -u in the root of module with no package in that root shouldn't fail, especially not with such an unclear error. Maybe it would make more sense to have an error that states explicitly how to, for example, update all of the module's dependencies, which is likely what someone running go get -u in the module root without a package is trying to do.

Documentation NeedsFix modules

Most helpful comment

go get without arguments is equivalent to go get .
And the argument . does not name a module.

~/go/src$ go list -m .
go: cannot use relative path . to specify module

If you want to update the dependencies of all packages within a module, you want go get -u -d ./....

We probably do need a clearer error message for this case.

All 6 comments

go get without arguments is equivalent to go get .
And the argument . does not name a module.

~/go/src$ go list -m .
go: cannot use relative path . to specify module

If you want to update the dependencies of all packages within a module, you want go get -u -d ./....

We probably do need a clearer error message for this case.

CC @jayconrod @matloob

https://golang.org/src/cmd/go/internal/modget/get.go#L342

go get .: no matching packages in module rooted at $pkgpath

How is this error message ?

@abemotion That doesn't seem much clearer than the current message.

The intent here is most likely to update dependencies for all packages in the main module, rather than the package at the root of the main module. So, specifically if 1) . is the only argument, 2) the working directory is the same as the module root directory, and 3) -u or -u=patch is set, we could print a hint after the error message:

go get: run 'go get -d -u ./...' to update the main module's dependencies

@jayconrod Thank you for your polite reply 😊

Your message is much clearer than my comment's one that doesn't have a hint.

+1 to a clearer error message - even something like use go get ./... to scan for modules in subdirectories would help

Was this page helpful?
0 / 5 - 0 ratings