Skip to content

Commit

Permalink
Merge pull request #517 from Jougan-0/errorHandlingForEmptyChartUrlAn…
Browse files Browse the repository at this point in the history
…dPackageNotFound

Error handling for EmptyChartUrl and PakcageNotFound w/signoff
  • Loading branch information
Mohd Uzair authored Jul 1, 2024
2 parents 8b2f3ab + ec9538d commit e00bcfa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions generators/artifacthub/error.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package artifacthub

import (
"fmt"

"github.com/layer5io/meshkit/errors"
)

Expand All @@ -9,6 +11,8 @@ var (
ErrGetAhPackageCode = "meshkit-11135"
ErrComponentGenerateCode = "meshkit-11136"
ErrGetAllHelmPackagesCode = "meshkit-11137"
ErrChartUrlEmptyCode = "replace_me"
ErrNoPackageFoundCode = "replace_me"
)

func ErrGetAllHelmPackages(err error) error {
Expand All @@ -26,3 +30,23 @@ func ErrGetAhPackage(err error) error {
func ErrComponentGenerate(err error) error {
return errors.New(ErrComponentGenerateCode, errors.Alert, []string{"failed to generate components for the package"}, []string{err.Error()}, []string{}, []string{"Make sure that the package is compatible"})
}
func ErrChartUrlEmpty(modelName string, registrantName string) error {
return errors.New(
ErrChartUrlEmptyCode,
errors.Alert,
[]string{fmt.Sprintf("The Chart URL for the %s model is empty.", modelName)},
[]string{fmt.Sprintf("provided Chart URL for the model %s is empty.", modelName)},
[]string{fmt.Sprintf("%s does not have Chart URL for %s", registrantName, modelName)},
[]string{fmt.Sprintf("Please provide the Chart URL for the model %s.", modelName)},
)
}
func ErrNoPackageFound(modelName string, registrantName string) error {
return errors.New(
ErrNoPackageFoundCode,
errors.Alert,
[]string{fmt.Sprintf("No package found for the model %s.", modelName)},
[]string{fmt.Sprintf("there was no package for %s model.", modelName)},
[]string{fmt.Sprintf("%s does not have any package for model name %s", registrantName, modelName)},
[]string{fmt.Sprintf("Please provide the correct package name for the model %s.", modelName)},
)
}
4 changes: 4 additions & 0 deletions generators/artifacthub/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (pkg AhPackage) GetVersion() string {
func (pkg AhPackage) GenerateComponents() ([]v1beta1.ComponentDefinition, error) {
components := make([]v1beta1.ComponentDefinition, 0)
// TODO: Move this to the configuration

if pkg.ChartUrl == "" {
return components, ErrChartUrlEmpty("Artifacthub", pkg.Name)
}
crds, err := manifests.GetCrdsFromHelm(pkg.ChartUrl)
if err != nil {
return components, ErrComponentGenerate(err)
Expand Down
3 changes: 3 additions & 0 deletions generators/artifacthub/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func (ahpm ArtifactHubPackageManager) GetPackage() (models.Package, error) {
if err != nil {
return nil, err
}
if len(pkgs) == 0 {
return nil, ErrNoPackageFound("Artifacthub", ahpm.PackageName)
}
// update package information
for i, ap := range pkgs {
_ = ap.UpdatePackageData()
Expand Down

0 comments on commit e00bcfa

Please sign in to comment.