Skip to content

Commit

Permalink
chore: implement error interface
Browse files Browse the repository at this point in the history
Signed-off-by: Armando Ruocco <[email protected]>
  • Loading branch information
armru committed Feb 19, 2024
1 parent af27643 commit fc67d5e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/operator/extensions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package operator

import (
"fmt"
"strings"
)

type ValidationErrors []ValidationError

// ContainsErrors returns true if the slice contains any ValidationError
func (v ValidationErrors) ContainsErrors() bool {
return len(v) > 0
}

func (v ValidationErrors) Error() string {
messages := make([]string, len(v))

for idx := range v {
validationError := &v[idx]
messages[idx] = validationError.Error()
}

return strings.Join(messages, ";")
}

func (v *ValidationError) Error() string {
return fmt.Sprintf(
"encountered a validation error, message: %s, value: %s, pathComponents: %s",
v.Message,
v.Value,
v.PathComponents,
)
}

0 comments on commit fc67d5e

Please sign in to comment.