From fc2c7613450a6fe3f2df727be0e4be603f8f65e4 Mon Sep 17 00:00:00 2001 From: Armando Ruocco Date: Mon, 19 Feb 2024 16:06:25 +0100 Subject: [PATCH] chore: implement error interface with the ValidationError struct (#23) Signed-off-by: Armando Ruocco --- pkg/operator/extensions.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pkg/operator/extensions.go diff --git a/pkg/operator/extensions.go b/pkg/operator/extensions.go new file mode 100644 index 0000000..9c70d61 --- /dev/null +++ b/pkg/operator/extensions.go @@ -0,0 +1,28 @@ +package operator + +import ( + "fmt" + "strings" +) + +type ValidationErrors []ValidationError + +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, + ) +}