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: suggestion to use go mod download does not work #50934

Open
findleyr opened this issue Jan 31, 2022 · 5 comments
Open

cmd/go: suggestion to use go mod download does not work #50934

findleyr opened this issue Jan 31, 2022 · 5 comments
Labels
GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@findleyr
Copy link
Contributor

I ran into this just now after upgrading x/mod in x/tools, running tests from the x/tools/gopls module:

[gopls]> go test ./internal/regtest/workspace
go: golang.org/x/tools@v0.1.7 requires
        golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3: missing go.sum entry; to add it:
        go mod download golang.org/x/mod
[gopls]> go mod download golang.org/x/mod
[gopls]> go test ./internal/regtest/workspace
go: golang.org/x/tools@v0.1.7 requires
        golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3: missing go.sum entry; to add it:
        go mod download golang.org/x/mod

The error message suggests that go mod download will fix the missing go.sum entry, but this does not work. I had to go mod tidy.
Can this suggestion be made more accurate?

This looks similar to #46528, but not quite a duplicate. Apologies if I missed another dupe.

CC @bcmills @matloob

@bcmills
Copy link
Contributor

bcmills commented Feb 1, 2022

I assume this was using a go at tip (near 1.18)?

@bcmills bcmills added GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 1, 2022
@findleyr
Copy link
Contributor Author

findleyr commented Feb 1, 2022

I assume this was using a go at tip (near 1.18)?

Yes: go version devel go1.18-9ff0039848 Fri Jan 28 02:40:34 2022 +0000 linux/amd64

@bcmills
Copy link
Contributor

bcmills commented Feb 1, 2022

Reproduced:

~/x/tools$ go version
go version devel go1.18-c8b0dcea4a Wed Jan 26 20:51:54 2022 +0000 linux/amd64

~/x/tools$ git status
On branch issue50934-mod-download
nothing to commit, working tree clean

~/x/tools$ git rev-parse HEAD
461d130035e971840054f875ee8e9da69440af8f

~/x/tools$ go get -d golang.org/x/mod@master
go: upgraded golang.org/x/mod v0.5.1 => v0.6.0-dev.0.20220106191415-9b9b3d81d5e3

~/x/tools$ cd gopls

~/x/tools/gopls$ go test ./internal/regtest/workspace
go: golang.org/x/tools@v0.1.8 requires
        golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3: missing go.sum entry; to add it:
        go mod download golang.org/x/mod

~/x/tools/gopls$ go mod download -json golang.org/x/mod
{
        "Path": "golang.org/x/mod",
        "Version": "v0.5.1",
        "Info": "/usr/local/google/home/bcmills/pkg/mod/cache/download/golang.org/x/mod/@v/v0.5.1.info",
        "GoMod": "/usr/local/google/home/bcmills/pkg/mod/cache/download/golang.org/x/mod/@v/v0.5.1.mod",
        "Zip": "/usr/local/google/home/bcmills/pkg/mod/cache/download/golang.org/x/mod/@v/v0.5.1.zip",
        "Dir": "/usr/local/google/home/bcmills/pkg/mod/golang.org/x/mod@v0.5.1",
        "Sum": "h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=",
        "GoModSum": "h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro="
}

@bcmills
Copy link
Contributor

bcmills commented Feb 1, 2022

This is kind of an edge-case interaction between replace, go mod download, and lazy module loading.

I think what's happening is:

  • Because the version of golang.org/x/mod is listed explicitly in gopls/go.mod, go mod download believes that that version (v0.5.1) is accurate and does not load the full module graph.
  • However, go test ./internal/regtest/workspace does load x/tools/go.mod, because it loads a package from x/tools and loading a package triggers a spot-check of the module's dependencies. That spot-check exposes two errors in the module graph: one is that the version of x/mod at the root of the graph is not the selected version, and the other is that some nodes in the module graph are missing checksums.
  • Because we didn't successfully load the module dependencies, we reported the checksum error instead of the inconsistent-version error.

This will probably need a bit more thought to get right. Perhaps if we fail to load the module graph we should report any known version-inconsistencies before we report checksum errors.

@seankhliao seankhliao added this to the Backlog milestone Aug 20, 2022
@PleasingFungus
Copy link

PleasingFungus commented Dec 14, 2022

I ran into something that looks like the same issue in franz-go today.

franz-go % cd examples/bench
bench % go build
go: github.com/twmb/franz-go@v1.5.3 requires
	github.com/klauspost/compress@v1.15.9: missing go.sum entry; to add it:
	go mod download github.com/klauspost/compress
bench % go mod download github.com/klauspost/compress
bench % go build
go: github.com/twmb/franz-go@v1.5.3 requires
	github.com/klauspost/compress@v1.15.9: missing go.sum entry; to add it:
	go mod download github.com/klauspost/compress

Running go mod tidy resolved it, with this diff to the go.sum:

-github.com/klauspost/compress v1.15.6 h1:6D9PcO8QWu0JyaQ2zUMmu16T1T+zjjEpP91guRsvDfY=
-github.com/klauspost/compress v1.15.6/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
+github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
+github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=

Would be great to see this fixed - it was very confusing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go 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