]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: handle NotExist errors in (*mvsReqs).Previous
authorBryan C. Mills <bcmills@google.com>
Thu, 29 Oct 2020 20:36:50 +0000 (16:36 -0400)
committerBryan C. Mills <bcmills@google.com>
Fri, 30 Oct 2020 18:06:13 +0000 (18:06 +0000)
Previous is used during downgrading. If the module proxy does not
advertise any versions (for example, because it contains only
pseudo-versions), then Previous should return "none" instead of a
non-nil error.

For #37438

Change-Id: I4edfec19cfeb3ffe50df4979f99a01321c442509
Reviewed-on: https://go-review.googlesource.com/c/go/+/266370
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/go/internal/modload/mvs.go

index 79ef2475b6a82f0509ba845ccf3856c3ec0b727f..94373bc5f39936ac705745bed2c2219920756029 100644 (file)
@@ -7,6 +7,7 @@ package modload
 import (
        "context"
        "errors"
+       "os"
        "sort"
 
        "cmd/go/internal/modfetch"
@@ -102,6 +103,9 @@ func (*mvsReqs) Previous(m module.Version) (module.Version, error) {
        // TODO(golang.org/issue/38714): thread tracing context through MVS.
        list, err := versions(context.TODO(), m.Path, CheckAllowed)
        if err != nil {
+               if errors.Is(err, os.ErrNotExist) {
+                       return module.Version{Path: m.Path, Version: "none"}, nil
+               }
                return module.Version{}, err
        }
        i := sort.Search(len(list), func(i int) bool { return semver.Compare(list[i], m.Version) >= 0 })