From ebf5d82c560e57af1268f5c7a81aa776c640e9e4 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 2 Aug 2023 00:48:27 +0200 Subject: [PATCH] fix: failover if no recipe meta available --- pkg/recipe/recipe.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index 64ce637b..f0b2a44f 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -236,9 +236,10 @@ func Get(recipeName string, conf *runtime.Config) (Recipe, error) { meta, err := GetRecipeMeta(recipeName, conf) if err != nil { - if strings.Contains(err.Error(), "does not exist") { + switch err.(type) { + case RecipeMissingFromCatalogue: meta = RecipeMeta{} - } else { + default: return Recipe{}, err } } @@ -368,7 +369,12 @@ func EnsureLatest(recipeName string, conf *runtime.Config) error { meta, err := GetRecipeMeta(recipeName, conf) if err != nil { - return err + switch err.(type) { + case RecipeMissingFromCatalogue: + meta = RecipeMeta{} + default: + return err + } } var branch plumbing.ReferenceName @@ -719,6 +725,14 @@ func VersionsOfService(recipe, serviceName string, conf *runtime.Config) ([]stri return versions, nil } +// RecipeMissingFromCatalogue signifies a recipe is not present in the catalogue. +type RecipeMissingFromCatalogue struct{ err string } + +// Error outputs the error message. +func (r RecipeMissingFromCatalogue) Error() string { + return r.err +} + // GetRecipeMeta retrieves the recipe metadata from the recipe catalogue. func GetRecipeMeta(recipeName string, conf *runtime.Config) (RecipeMeta, error) { catl, err := ReadRecipeCatalogue(conf) @@ -728,7 +742,9 @@ func GetRecipeMeta(recipeName string, conf *runtime.Config) (RecipeMeta, error) recipeMeta, ok := catl[recipeName] if !ok { - return RecipeMeta{}, fmt.Errorf("recipe %s does not exist?", recipeName) + return RecipeMeta{}, RecipeMissingFromCatalogue{ + err: fmt.Sprintf("recipe %s does not exist?", recipeName), + } } if err := EnsureExists(recipeName, conf); err != nil {