Open
Description
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
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
marwan-at-work commentedon Jan 28, 2021
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 rungo 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:
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 commentedon Jan 28, 2021
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 (orgo 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 thego run
command:go build
behavior changes seem detrimental to developer flow #44212gopherbot commentedon Mar 4, 2021
Change https://golang.org/cl/298650 mentions this issue:
cmd/go: clarify errors for commands run outside a module