]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch: distinguish "unsupported" errors from RecentTag
authorBryan C. Mills <bcmills@google.com>
Mon, 29 Aug 2022 20:27:00 +0000 (16:27 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 29 Aug 2022 21:29:04 +0000 (21:29 +0000)
CL 426079 started checking errors from RecentTag.
Unfortunately, we forgot to run "-longtest" SlowBots, and it turns out
to have broken non-short tests for non-git VCS implementations,
because those don't implement the RecentTag method.

Updates #53935.

Change-Id: I5935f2f4b3f684515e99e8bf70a840154c36249f
Reviewed-on: https://go-review.googlesource.com/c/go/+/426495
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/modfetch/codehost/codehost.go
src/cmd/go/internal/modfetch/codehost/vcs.go
src/cmd/go/internal/modfetch/coderepo.go

index 3a6e55e9a36f60136a5d31b74d7dad455be5bdc4..855b6946ca4e42f7985541b71a9e2ab5de445e45 100644 (file)
@@ -201,6 +201,19 @@ func (noCommitsError) Is(err error) bool {
        return err == fs.ErrNotExist
 }
 
+// ErrUnsupported indicates that a requested operation cannot be performed,
+// because it is unsupported. This error indicates that there is no alternative
+// way to perform the operation.
+//
+// TODO(#41198): Remove this declaration and use errors.ErrUnsupported instead.
+var ErrUnsupported = unsupportedOperationError{}
+
+type unsupportedOperationError struct{}
+
+func (unsupportedOperationError) Error() string {
+       return "unsupported operation"
+}
+
 // AllHex reports whether the revision rev is entirely lower-case hexadecimal digits.
 func AllHex(rev string) bool {
        for i := 0; i < len(rev); i++ {
index f1c40998b2296fecd4c9a33f7c21972b5401336d..4d0e863182b3fc3a1e91d174032ebfc04aa0de36 100644 (file)
@@ -38,6 +38,8 @@ type VCSError struct {
 
 func (e *VCSError) Error() string { return e.Err.Error() }
 
+func (e *VCSError) Unwrap() error { return e.Err }
+
 func vcsErrorf(format string, a ...any) error {
        return &VCSError{Err: fmt.Errorf(format, a...)}
 }
@@ -290,10 +292,8 @@ func (r *vcsRepo) loadBranches() {
        }
 }
 
-var ErrNoRepoHash = errors.New("RepoHash not supported")
-
 func (r *vcsRepo) CheckReuse(old *Origin, subdir string) error {
-       return fmt.Errorf("vcs %s does not implement CheckReuse", r.cmd.vcs)
+       return fmt.Errorf("vcs %s: CheckReuse: %w", r.cmd.vcs, ErrUnsupported)
 }
 
 func (r *vcsRepo) Tags(prefix string) (*Tags, error) {
@@ -417,7 +417,7 @@ func (r *vcsRepo) RecentTag(rev, prefix string, allowed func(string) bool) (tag
        }
        defer unlock()
 
-       return "", vcsErrorf("RecentTag not implemented")
+       return "", vcsErrorf("vcs %s: RecentTag: %w", r.cmd.vcs, ErrUnsupported)
 }
 
 func (r *vcsRepo) DescendsFrom(rev, tag string) (bool, error) {
@@ -427,12 +427,12 @@ func (r *vcsRepo) DescendsFrom(rev, tag string) (bool, error) {
        }
        defer unlock()
 
-       return false, vcsErrorf("DescendsFrom not implemented")
+       return false, vcsErrorf("vcs %s: DescendsFrom: %w", r.cmd.vcs, ErrUnsupported)
 }
 
 func (r *vcsRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser, err error) {
        if r.cmd.readZip == nil && r.cmd.doReadZip == nil {
-               return nil, vcsErrorf("ReadZip not implemented for %s", r.cmd.vcs)
+               return nil, vcsErrorf("vcs %s: ReadZip: %w", r.cmd.vcs, ErrUnsupported)
        }
 
        unlock, err := r.mu.Lock()
index 138c00da19e79888f0eb358c5e8a13c0bdee73b6..b72989b2a856200d7487cedecd211d49a904b9e4 100644 (file)
@@ -608,7 +608,7 @@ func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, e
        }
        if pseudoBase == "" {
                tag, err := r.code.RecentTag(info.Name, tagPrefix, tagAllowed)
-               if err != nil {
+               if err != nil && !errors.Is(err, codehost.ErrUnsupported) {
                        return nil, err
                }
                if tag != "" {