mirror of https://github.com/helm/helm.git
fix(sdk): Polish the downloader/manager package error return (#8491)
* fix(sdk): Polish the downloader/manager package error return Close #8471 Signed-off-by: Dong Gang <dong.gang@daocloud.io> * Modify the repositories validation function `resloveRepoNames` and add a unit test. Signed-off-by: Dong Gang <dong.gang@daocloud.io> * Remove wrong commit Signed-off-by: Dong Gang <dong.gang@daocloud.io>
This commit is contained in:
parent
241785c70f
commit
ffc3d42f87
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -65,7 +66,11 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command {
|
|||
if client.Verify {
|
||||
man.Verify = downloader.VerifyIfPossible
|
||||
}
|
||||
return man.Build()
|
||||
err := man.Build()
|
||||
if e, ok := err.(downloader.ErrRepoNotFound); ok {
|
||||
return fmt.Errorf("%s. Please add the missing repos via 'helm repo add'", e.Error())
|
||||
}
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,17 @@ import (
|
|||
"helm.sh/helm/v3/pkg/repo"
|
||||
)
|
||||
|
||||
// ErrRepoNotFound indicates that chart repositories can't be found in local repo cache.
|
||||
// The value of Repos is missing repos.
|
||||
type ErrRepoNotFound struct {
|
||||
Repos []string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrRepoNotFound) Error() string {
|
||||
return fmt.Sprintf("no repository definition for %s", strings.Join(e.Repos, ", "))
|
||||
}
|
||||
|
||||
// Manager handles the lifecycle of fetching, resolving, and storing dependencies.
|
||||
type Manager struct {
|
||||
// Out is used to print warnings and notifications.
|
||||
|
@ -411,7 +422,7 @@ Loop:
|
|||
missing = append(missing, dd.Repository)
|
||||
}
|
||||
if len(missing) > 0 {
|
||||
return errors.Errorf("no repository definition for %s. Please add the missing repos via 'helm repo add'", strings.Join(missing, ", "))
|
||||
return ErrRepoNotFound{missing}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -360,3 +360,32 @@ func TestBuild_WithRepositoryAlias(t *testing.T) {
|
|||
Repository: "@test",
|
||||
})
|
||||
}
|
||||
|
||||
func TestErrRepoNotFound_Error(t *testing.T) {
|
||||
type fields struct {
|
||||
Repos []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "OK",
|
||||
fields: fields{
|
||||
Repos: []string{"https://charts1.example.com", "https://charts2.example.com"},
|
||||
},
|
||||
want: "no repository definition for https://charts1.example.com, https://charts2.example.com",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
e := ErrRepoNotFound{
|
||||
Repos: tt.fields.Repos,
|
||||
}
|
||||
if got := e.Error(); got != tt.want {
|
||||
t.Errorf("Error() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue