Skip to content

cmd/go: 'go mod edit -exclude' erroneously rejects '+incompatible' versions #44497

Closed
@bcmills

Description

@bcmills

In CL 279394 and CL 283853, we added version validation for the -retract and -exclude flags of the go mod edit command.

Unfortunately, something about that validation is off: go mod edit -exclude with a +incompatible version should succeed (and does with go 1.15.8), but instead it fails with version … invalid: must be of the form v1.2.3.

In CL 279394 we are calling semver.Canonical, but in light of this bug I believe we should be using module.CanonicalVersion instead. (The two are very easily confused, and we missed this problem during code-review and testing.)

#44494 may or may not be related. (I noticed this while investigating go-chi/chi#561.)

$ go version
go version devel +0f66fb7b8 Sun Feb 21 02:25:41 2021 +0000 linux/amd64

$ go mod init example.com
go: creating new go.mod: module example.com

$ go get -d github.com/99designs/gqlgen
go: downloading github.com/99designs/gqlgen v0.13.0
go: downloading github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e
go: downloading github.com/matryer/moq v0.0.0-20200106131100-75d0ddfc0007
go: downloading github.com/pkg/errors v0.8.1
go: downloading github.com/urfave/cli/v2 v2.1.1
go: downloading github.com/vektah/gqlparser/v2 v2.1.0
go: downloading gopkg.in/yaml.v2 v2.2.4
go: downloading github.com/gorilla/websocket v1.4.2
go: downloading golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589
go: downloading github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047
go: downloading github.com/hashicorp/golang-lru v0.5.0
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d
go: downloading github.com/agnivade/levenshtein v1.0.3
go: downloading github.com/russross/blackfriday/v2 v2.0.1
go: downloading github.com/shurcooL/sanitized_anchor_name v1.0.0
go get: added github.com/99designs/gqlgen v0.13.0

$ go list -m github.com/go-chi/chi
github.com/go-chi/chi v3.3.2+incompatible

$ go mod edit -exclude github.com/go-chi/[email protected]+incompatible
go mod: -exclude=github.com/go-chi/[email protected]+incompatible: version "v3.3.2+incompatible" invalid: must be of the form v1.2.3

$ go1.15.8 mod edit -exclude github.com/go-chi/[email protected]+incompatible

$ go list -m github.com/go-chi/chi
go list -m: module github.com/go-chi/chi: not a known dependency

CC @jayconrod @matloob

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions