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 · 4 comments
Open

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

findleyr opened this issue Jan 31, 2022 · 4 comments
Labels
GoCommand modules NeedsInvestigation

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented Jan 31, 2022

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
Member

@bcmills bcmills commented Feb 1, 2022

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

@bcmills bcmills added GoCommand modules NeedsInvestigation labels Feb 1, 2022
@findleyr
Copy link
Contributor Author

@findleyr 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
Member

@bcmills 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
Member

@bcmills 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand modules NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

2 participants