From 9b97e23889f7f63e7a5d433511be7f1db96f23d8 Mon Sep 17 00:00:00 2001 From: SIGSEGV Date: Wed, 10 Mar 2021 12:16:54 +0800 Subject: [PATCH] Fix the issue that old nighlty may cause error (#1198) --- pkg/environment/env.go | 3 +++ pkg/repository/v1_repository.go | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/environment/env.go b/pkg/environment/env.go index 0bc2614b94..86d9f1ac38 100644 --- a/pkg/environment/env.go +++ b/pkg/environment/env.go @@ -259,6 +259,9 @@ func (env *Environment) SelectInstalledVersion(component string, ver pkgver.Vers versions := []string{} for _, v := range installed { vi, err := env.v1Repo.ComponentVersion(component, v, true) + if errors.Cause(err) == repository.ErrUnknownVersion { + continue + } if err != nil { return ver, err } diff --git a/pkg/repository/v1_repository.go b/pkg/repository/v1_repository.go index a80bc0e287..d423539bda 100644 --- a/pkg/repository/v1_repository.go +++ b/pkg/repository/v1_repository.go @@ -17,7 +17,6 @@ import ( "bytes" "crypto/sha256" "encoding/hex" - stderrors "errors" "fmt" "io" "os" @@ -41,7 +40,10 @@ import ( ) // ErrUnknownComponent represents the specific component cannot be found in index.json -var ErrUnknownComponent = stderrors.New("unknown component") +var ErrUnknownComponent = errors.New("unknown component") + +// ErrUnknownVersion represents the specific component version cannot be found in component.json +var ErrUnknownVersion = errors.New("unknown version") // V1Repository represents a remote repository viewed with the v1 manifest design. type V1Repository struct { @@ -724,7 +726,7 @@ func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1 } vi := manifest.VersionItem(r.PlatformString(), ver, includeYanked) if vi == nil { - return nil, errors.Errorf("version %s on %s for component %s not found", ver, r.PlatformString(), id) + return nil, errors.Annotatef(ErrUnknownVersion, "version %s on %s for component %s not found", ver, r.PlatformString(), id) } return vi, nil }