@@ -23,7 +23,8 @@ package shared
23
23
import (
24
24
"fmt"
25
25
"io"
26
- goStrings "strings"
26
+
27
+ "github.com/arangodb/kube-arangodb/pkg/util/errors"
27
28
)
28
29
29
30
type ResourceError struct {
@@ -84,38 +85,16 @@ func PrefixResourceErrors(prefix string, errs ...error) error {
84
85
85
86
for _ , err := range errs {
86
87
switch errType := err .(type ) {
87
- case MergedErrors :
88
- for _ , subError := range errType . errors {
88
+ case errors. Array :
89
+ for _ , subError := range errType {
89
90
prefixed = append (prefixed , PrefixResourceError (prefix , subError ))
90
91
}
91
92
default :
92
93
prefixed = append (prefixed , PrefixResourceError (prefix , err ))
93
94
}
94
95
}
95
96
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 ... )
119
98
}
120
99
121
100
// WithErrors filter out nil errors
@@ -128,18 +107,12 @@ func WithErrors(errs ...error) error {
128
107
}
129
108
130
109
switch errType := err .(type ) {
131
- case MergedErrors :
132
- filteredErrs = append (filteredErrs , errType .errors . .. )
110
+ case errors. Array :
111
+ filteredErrs = append (filteredErrs , errType ... )
133
112
default :
134
113
filteredErrs = append (filteredErrs , err )
135
114
}
136
115
}
137
116
138
- if len (filteredErrs ) == 0 {
139
- return nil
140
- }
141
-
142
- return MergedErrors {
143
- errors : filteredErrs ,
144
- }
117
+ return errors .Errors (filteredErrs ... )
145
118
}
0 commit comments