Skip to content

cmd/go: misleading "invalid version" error message for gopkg.in modules with mismatched module path #43809

@jayconrod

Description

@jayconrod

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

$ go version
go version go1.16beta1 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jayconrod/Library/Caches/go-build"
GOENV="/Users/jayconrod/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jayconrod/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jayconrod/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go/installed"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/installed/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16beta1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jayconrod/Code/test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rq/x0692kqj6ml8cvrhcqh5bswc008xj1/T/go-build892501000=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Run go mod download on a module with a gopkg.in module path, when the actual go.mod file has a different module path.

go mod download gopkg.in/golang/mock.v1@v1.4.4

What did you expect to see?

go mod download should succeed. go get and anything else that actually loads the module graph should fail with a mismatched module path error message.

In general, go mod download should succeed when the module path on the command line doesn't match the actual module path in go.mod. If it didn't, module version replacements wouldn't work. For example, go mod download github.com/google/go-cloud@v0.21.0 works even though it declares itself as gocloud.dev.

It's fine that the go command checks that the version matches the major version suffix, but it should check that against the module path named on the command line, not the module path in go.mod.

What did you see instead?

go mod download: gopkg.in/golang/mock.v1@v1.4.4: invalid version: go.mod has non-....v1 module path "github.com/golang/mock" at revision v1.4.4

gopkg.in module paths must have a major version suffix, in this case, .v1. The go command is reporting that the actual module path in go.mod, github.com/golang/mock does not end with .v1.

cc @bcmills @matloob @julieqiu

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions