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: consolidate similar hint commands printed with errors #43653

Open
jayconrod opened this issue Jan 12, 2021 · 3 comments
Open

cmd/go: consolidate similar hint commands printed with errors #43653

jayconrod opened this issue Jan 12, 2021 · 3 comments
Labels
modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@jayconrod
Copy link
Contributor

In Go 1.16, the go command will suggest commands the user can run to fix common errors in go.mod and go.sum like missing requirements and sums. These hints are important, since a few errors will become a lot more common with -mod=readonly enabled by default (#40728); previously, these errors were fixed automatically by go build, go list, and other commands.

In some cases, different variations of the same hint may be printed several times. For example, the project below has a go.sum file with some missing sums.

go build .

-- use.go --
package use

import (
	_ "golang.org/x/mod/semver"
	_ "golang.org/x/tools/go/packages"
)
-- go.mod --
module m

go 1.16

require (
	golang.org/x/mod v0.4.0
	golang.org/x/tools v0.0.0-20210111221946-d33bae441459
)
-- go.sum --
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20210111221946-d33bae441459/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

The command go build . prints the two errors below:

use.go:4:2: missing go.sum entry for module providing package golang.org/x/mod/semver; to add:
	go get golang.org/x/mod/semver@v0.4.0
use.go:5:2: missing go.sum entry for module providing package golang.org/x/tools/go/packages; to add:
	go get golang.org/x/tools/go/packages@v0.0.0-20210111221946-d33bae441459

When there are similar errors like this, we should try to consolidate them. In this case, we should print something like:

missing go.sum entries for multiple modules; to add:
	go get m

cc @bcmills @matloob

@jayconrod jayconrod added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 12, 2021
@jayconrod jayconrod added this to the Backlog milestone Jan 12, 2021
@marwan-at-work
Copy link
Contributor

Hi @jayconrod ,

I think I am experiencing a similar issue that I thought I'd add here (let me know if it's different and I'm happy to open a new issue).

The issue happens with Facebook's ent library: github.com/facebook/ent

The library (similar to protobufs and twirp) has a code generator and also is expected to be imported directly and therefore it's a best practice to make sure the code generator and the library are both always the same version.

Therefore, the library recommends that instead of installing the binary and running it like so ent generate ./schema, you instead directly run go run github.com/facebook/ent/cmd/ent ./schema from your module so that the versions are exactly the same since Go will use the module's go.mod file.

In Go 1.15, things worked fine. But in 1.16 I get the following error:

../../../go/pkg/mod/github.com/facebook/ent@v0.5.5-0.20210124175728-2c7228c23fd9/entc/gen/func.go:22:2: missing go.sum entry for module providing package github.com/go-openapi/inflect (imported by github.com/facebook/ent/entc/gen); to add:
        go get github.com/facebook/ent/entc/gen@v0.5.5-0.20210124175728-2c7228c23fd9
../../../go/pkg/mod/github.com/facebook/ent@v0.5.5-0.20210124175728-2c7228c23fd9/cmd/internal/printer/printer.go:16:2: missing go.sum entry for module providing package github.com/olekukonko/tablewriter (imported by github.com/facebook/ent/cmd/internal/printer); to add:
        go get github.com/facebook/ent/cmd/internal/printer@v0.5.5-0.20210124175728-2c7228c23fd9
../../../go/pkg/mod/github.com/facebook/ent@v0.5.5-0.20210124175728-2c7228c23fd9/cmd/internal/base/base.go:25:2: missing go.sum entry for module providing package github.com/spf13/cobra (imported by github.com/facebook/ent/cmd/ent); to add:
        go get github.com/facebook/ent/cmd/ent@v0.5.5-0.20210124175728-2c7228c23fd9
../../../go/pkg/mod/github.com/facebook/ent@v0.5.5-0.20210124175728-2c7228c23fd9/entc/load/load.go:29:2: missing go.sum entry for module providing package golang.org/x/tools/go/packages (imported by github.com/facebook/ent/cmd/internal/base); to add:
        go get github.com/facebook/ent/cmd/internal/base@v0.5.5-0.20210124175728-2c7228c23fd9
../../../go/pkg/mod/github.com/facebook/ent@v0.5.5-0.20210124175728-2c7228c23fd9/entc/gen/graph.go:24:2: missing go.sum entry for module providing package golang.org/x/tools/imports (imported by github.com/facebook/ent/entc/gen); to add:
        go get github.com/facebook/ent/entc/gen@v0.5.5-0.20210124175728-2c7228c23fd9

I have created a repro with a readme here: here https://github.com/marwan-at-work/enterr

Of course, we can also pass -mod=mod but I imagine that defeats the purpose of -mod=readonly?

Thanks!

@jayconrod
Copy link
Contributor Author

Thanks @marwan-at-work, I think this is the same issue viewed from another angle.

I think the best thing to recommend here is to define a dummy package that imports tools (#25922), then go get -d that package (or go mod tidy). That will pull in all the sums that tools need.

I don't think the go command should recommend all of that though. If this issue were fixed, it would suggest something like this, based on the go run command:

go get -d github.com/facebook/ent/cmd/ent@v0.5.5-0.20210124175728-2c7228c23fd9

@gopherbot
Copy link

Change https://golang.org/cl/298650 mentions this issue: cmd/go: clarify errors for commands run outside a module

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

No branches or pull requests

4 participants