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: improve error message for mismatched major versions #41512

Open
glycerine opened this issue Sep 20, 2020 · 4 comments
Open

cmd/go: improve error message for mismatched major versions #41512

glycerine opened this issue Sep 20, 2020 · 4 comments
Labels
Milestone

Comments

@glycerine
Copy link

@glycerine glycerine commented Sep 20, 2020

related to
#35732
which remains the top google hit for this error

what does one do to get this simple example to work?

jaten@jatens-MacBook-Pro ~/etcd-embed $ go build
go: errors parsing go.mod:
/Users/jaten/etcd-embed/go.mod:3: require go.etcd.io/etcd: version "v3.4.13" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v3
jaten@jatens-MacBook-Pro ~/etcd-embed $ go version
go version go1.14.4 darwin/amd64
jaten@jatens-MacBook-Pro ~/etcd-embed $ cat go.mod
module github.com/glycerine/etcd-embed

require go.etcd.io/etcd v3.4.13
                                      
go 1.14

          
jaten@jatens-MacBook-Pro ~/etcd-embed $ cat main.go
package main

import (
	"log"
	"time"

	"go.etcd.io/etcd/v3/embed"
)

func main() {
	cfg := embed.NewConfig()
	cfg.Dir = "default.etcd"
	e, err := embed.StartEtcd(cfg)
	if err != nil {
		log.Fatal(err)
	}
	defer e.Close()
	select {
	case <-e.Server.ReadyNotify():
		log.Printf("Server is ready!")
	case <-time.After(60 * time.Second):
		e.Server.Stop() // trigger a shutdown
		log.Printf("Server took too long to start!")
	}
	log.Fatal(<-e.Err())
}
jaten@jatens-MacBook-Pro ~/etcd-embed $

if I change go.mod to

module github.com/glycerine/etcd-embed

require go.etcd.io/etcd/v3 v3.4.13

go 1.14

I get the equally mystifying

jaten@jatens-MacBook-Pro ~/etcd-embed $ go build
go: go.etcd.io/etcd/v3@v3.4.13: go.mod has non-.../v3 module path "go.etcd.io/etcd" (and .../v3/go.mod does not exist) at revision v3.4.13
jaten@jatens-MacBook-Pro ~/etcd-embed $
@andig
Copy link
Contributor

@andig andig commented Sep 21, 2020

Imho v3 denotes a v3 major module version. Seems your module in question is v1 (although it has a 3.xyz version number), so omit the /v3 suffix when requiring it. While this sounds confusing it is imho due to keeping backwards compatibility with modules what introduced versioning before go.mod came around in go 1.11.

@andig
Copy link
Contributor

@andig andig commented Sep 21, 2020

Imho you need to change the module path to the github-hosted one which declares itself as v3.

@bcmills bcmills changed the title unacceptably poor UX for go.mod: invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v3 cmd/go: improve error message for mismatched major versions Sep 21, 2020
@bcmills
Copy link
Member

@bcmills bcmills commented Sep 21, 2020

As noted in #35732 (comment):

[W]e do want to make the errors as clear as possible. If you have a specific improvement to suggest in the phrasing of the error, please open a new issue (or send a change with the proposed improvement)!

That said, I've been thinking about this particular error message some more. I think the error message we've written today assumes that the module path is correct and the version is wrong (because it doesn't match the module path), when really most users who encounter this error really have written the version they intend: we should suggest a fix to the path, not to the version.

CC @jayconrod @matloob

@bcmills
Copy link
Member

@bcmills bcmills commented Sep 21, 2020

@glycerine, in this case, the problem is that the latest v3-tagged release of go.etcd.io/etcd (v3.4.13) has declared the wrong module path for that major version (it should instead be go.etcd.io/etcd/v3). That issue has been fixed at head (etcd-io/etcd@96cce20), but not yet included in a tagged release. (That is etcd-io/etcd#12068 / etcd-io/etcd#12109.)

The go command intentionally does not try untagged commits when a release tag exists for the requested major version, but you could fetch such a commit explicitly using go get -d go.etcd.io/etcd/v3@master.

@bcmills bcmills added this to the Go1.16 milestone Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.