@@ -23,7 +23,8 @@ package shared
2323import (
2424 "fmt"
2525 "io"
26- goStrings "strings"
26+
27+ "github.com/arangodb/kube-arangodb/pkg/util/errors"
2728)
2829
2930type ResourceError struct {
@@ -84,38 +85,16 @@ func PrefixResourceErrors(prefix string, errs ...error) error {
8485
8586 for _ , err := range errs {
8687 switch errType := err .(type ) {
87- case MergedErrors :
88- for _ , subError := range errType . errors {
88+ case errors. Array :
89+ for _ , subError := range errType {
8990 prefixed = append (prefixed , PrefixResourceError (prefix , subError ))
9091 }
9192 default :
9293 prefixed = append (prefixed , PrefixResourceError (prefix , err ))
9394 }
9495 }
9596
96- return WithErrors (prefixed ... )
97- }
98-
99- type MergedErrors struct {
100- errors []error
101- }
102-
103- func (m MergedErrors ) Error () string {
104- errStrings := make ([]string , 0 , len (m .errors ))
105-
106- for _ , err := range m .errors {
107- if err == nil {
108- continue
109- }
110-
111- errStrings = append (errStrings , err .Error ())
112- }
113-
114- return fmt .Sprintf ("Received %d errors: %s" , len (errStrings ), goStrings .Join (errStrings , ", " ))
115- }
116-
117- func (m MergedErrors ) Errors () []error {
118- return m .errors
97+ return errors .Errors (prefixed ... )
11998}
12099
121100// WithErrors filter out nil errors
@@ -128,18 +107,12 @@ func WithErrors(errs ...error) error {
128107 }
129108
130109 switch errType := err .(type ) {
131- case MergedErrors :
132- filteredErrs = append (filteredErrs , errType .errors . .. )
110+ case errors. Array :
111+ filteredErrs = append (filteredErrs , errType ... )
133112 default :
134113 filteredErrs = append (filteredErrs , err )
135114 }
136115 }
137116
138- if len (filteredErrs ) == 0 {
139- return nil
140- }
141-
142- return MergedErrors {
143- errors : filteredErrs ,
144- }
117+ return errors .Errors (filteredErrs ... )
145118}
0 commit comments