Skip to content

Commit

Permalink
Wait for go1.21 to use errors.Join for now use an adhoc wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Mustafa Abdelrahman <[email protected]>
  • Loading branch information
MustafaSaber committed Aug 1, 2023
1 parent e3ef80e commit e8ed695
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions dataclients/kubernetes/definitions/routegroupvalidator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package definitions

import (
"errors"
"fmt"

"github.com/zalando/skipper/eskip"
)
Expand All @@ -18,19 +18,32 @@ func ValidateRouteGroup(rg *RouteGroupItem) error {
func ValidateRouteGroupList(rgl RouteGroupList) error {
var err error
for _, rg := range rgl.Items {
err = errors.Join(err, defaultRouteGroupValidator.Validate(rg))
// TODO: Use errors.Join
err = wrapError(err, defaultRouteGroupValidator.Validate(rg))
}
return err
}

func wrapError(err1 error, err2 error) error {
if err1 == nil && err2 == nil {
return nil
} else if err1 == nil {
return err2
} else if err2 == nil {
return err1
} else {
return fmt.Errorf("%w\n%w", err1, err2)
}
}

func (rgv *RouteGroupValidator) Validate(item *RouteGroupItem) error {
err := rgv.basicValidation(item)
if err != nil {
return err
}
err = errors.Join(err, rgv.filtersValidation(item))

err = errors.Join(err, rgv.predicatesValidation(item))
err = wrapError(err, rgv.filtersValidation(item))
// TODO: Use errors.Join
err = wrapError(err, rgv.predicatesValidation(item))

return err
}
Expand Down Expand Up @@ -59,7 +72,8 @@ func (rgv *RouteGroupValidator) filtersValidation(item *RouteGroupItem) error {
for _, r := range item.Spec.Routes {
for _, f := range r.Filters {
_, e := eskip.ParseFilters(f)
err = errors.Join(err, e)
// TODO: Use errors.Join
err = wrapError(err, e)
}
}

Expand All @@ -71,7 +85,8 @@ func (rgv *RouteGroupValidator) predicatesValidation(item *RouteGroupItem) error
for _, r := range item.Spec.Routes {
for _, p := range r.Predicates {
_, e := eskip.ParsePredicates(p)
err = errors.Join(err, e)
// TODO: Use errors.Join
err = wrapError(err, e)
}
}
return err
Expand Down

0 comments on commit e8ed695

Please sign in to comment.