fix: failover if no recipe meta available
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
decentral1se 2023-08-02 00:48:27 +02:00
parent 2cd453ae8d
commit ebf5d82c56
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
1 changed files with 20 additions and 4 deletions

View File

@ -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 {