From: Bryan C. Mills Date: Mon, 29 Aug 2022 20:27:00 +0000 (-0400) Subject: cmd/go/internal/modfetch: distinguish "unsupported" errors from RecentTag X-Git-Tag: go1.20rc1~1352 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7b689dcbefbe5442b8b59a56efc1eced4fce233c;p=gostls13.git cmd/go/internal/modfetch: distinguish "unsupported" errors from RecentTag 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 Reviewed-by: David Chase Reviewed-by: Dmitri Shuralyov Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot --- diff --git a/src/cmd/go/internal/modfetch/codehost/codehost.go b/src/cmd/go/internal/modfetch/codehost/codehost.go index 3a6e55e9a3..855b6946ca 100644 --- a/src/cmd/go/internal/modfetch/codehost/codehost.go +++ b/src/cmd/go/internal/modfetch/codehost/codehost.go @@ -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++ { diff --git a/src/cmd/go/internal/modfetch/codehost/vcs.go b/src/cmd/go/internal/modfetch/codehost/vcs.go index f1c40998b2..4d0e863182 100644 --- a/src/cmd/go/internal/modfetch/codehost/vcs.go +++ b/src/cmd/go/internal/modfetch/codehost/vcs.go @@ -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() diff --git a/src/cmd/go/internal/modfetch/coderepo.go b/src/cmd/go/internal/modfetch/coderepo.go index 138c00da19..b72989b2a8 100644 --- a/src/cmd/go/internal/modfetch/coderepo.go +++ b/src/cmd/go/internal/modfetch/coderepo.go @@ -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 != "" {