mirror of
https://github.com/golang/go
synced 2024-11-12 00:20:22 -07:00
cmd/go/internal/modload: don't query when fixing canonical versions
If a canonical version is passed to fixVersion when loading the main go.mod and that version don't match the module path's major version suffix, don't call Query. Query doesn't return a useful error in this case when the path is malformed, for example, when it doens't have a dot in the first path element. It's better to report the major version mismatch error. Fixes #44494 Change-Id: I97b1f64aee894fa0db6fb637aa03a51357ee782c Reviewed-on: https://go-review.googlesource.com/c/go/+/296590 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
2a8df4488e
commit
5fafc0bbd4
@ -539,9 +539,10 @@ func fixVersion(ctx context.Context, fixed *bool) modfile.VersionFixer {
|
||||
}
|
||||
}
|
||||
if vers != "" && module.CanonicalVersion(vers) == vers {
|
||||
if err := module.CheckPathMajor(vers, pathMajor); err == nil {
|
||||
return vers, nil
|
||||
if err := module.CheckPathMajor(vers, pathMajor); err != nil {
|
||||
return "", module.VersionError(module.Version{Path: path, Version: vers}, err)
|
||||
}
|
||||
return vers, nil
|
||||
}
|
||||
|
||||
info, err := Query(ctx, path, vers, "", nil)
|
||||
|
@ -12,6 +12,18 @@ go mod tidy
|
||||
go list -m all
|
||||
cmp go.mod go.mod.want
|
||||
|
||||
# If a retracted version doesn't match the module's major version suffx,
|
||||
# an error should be reported.
|
||||
! go mod edit -retract=v3.0.1
|
||||
stderr '^go mod: -retract=v3.0.1: version "v3.0.1" invalid: should be v2, not v3$'
|
||||
cp go.mod.mismatch-v2 go.mod
|
||||
! go list -m all
|
||||
stderr 'go.mod:3: retract rsc.io/quote/v2: version "v3.0.1" invalid: should be v2, not v3$'
|
||||
|
||||
cp go.mod.mismatch-v1 go.mod
|
||||
! go list -m all
|
||||
stderr 'go.mod:3: retract rsc.io/quote: version "v3.0.1" invalid: should be v0 or v1, not v3$'
|
||||
|
||||
-- go.mod --
|
||||
go 1.16
|
||||
|
||||
@ -22,3 +34,15 @@ go 1.16
|
||||
retract v2.0.1
|
||||
|
||||
module rsc.io/quote/v2
|
||||
-- go.mod.mismatch-v2 --
|
||||
go 1.16
|
||||
|
||||
retract v3.0.1
|
||||
|
||||
module rsc.io/quote/v2
|
||||
-- go.mod.mismatch-v1 --
|
||||
go 1.16
|
||||
|
||||
retract v3.0.1
|
||||
|
||||
module rsc.io/quote
|
||||
|
Loading…
Reference in New Issue
Block a user