-
Notifications
You must be signed in to change notification settings - Fork 22
/
error.go
227 lines (177 loc) · 5.45 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package tccp
import (
"fmt"
"strings"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/giantswarm/microerror"
)
// executionFailedError is an error type for situations where Resource execution
// cannot continue and must always fall back to operatorkit.
//
// This error should never be matched against and therefore there is no matcher
// implement. For further information see:
//
// https://github.com/giantswarm/fmt/blob/master/go/errors.md#matching-errors
var executionFailedError = µerror.Error{
Kind: "executionFailedError",
}
// event... is an error type for situations where we want to create an Kubernetes event in operatorkit.
var eventCFCreateError = µerror.Error{
Kind: "CFCreateFailed",
Desc: fmt.Sprintf("The tenant cluster's control plane cloud formation stack has stack status %#q", cloudformation.StackStatusCreateFailed),
}
var eventCFUpdateRollbackError = µerror.Error{
Kind: "CFUpdateRollbackFailed",
Desc: fmt.Sprintf("The tenant cluster's control plane cloud formation stack has stack status %#q", cloudformation.StackStatusUpdateRollbackFailed),
}
var eventCFRollbackError = µerror.Error{
Kind: "CFRollbackFailed",
Desc: fmt.Sprintf("The tenant cluster's control plane cloud formation stack has stack status %#q", cloudformation.StackStatusRollbackFailed),
}
var eventCFDeleteError = µerror.Error{
Kind: "CFDeleteFailed",
Desc: fmt.Sprintf("The tenant cluster's control plane cloud formation stack has stack status %#q", cloudformation.StackStatusDeleteFailed),
}
// IsDeleteFailed asserts eventCFDeleteError.
func IsDeleteFailed(err error) bool {
c := microerror.Cause(err)
if c == nil {
return false
}
if strings.Contains(c.Error(), cloudformation.ResourceStatusDeleteFailed) {
return true
}
if c == eventCFDeleteError {
return true
}
return false
}
var alreadyTerminatedError = µerror.Error{
Kind: "alreadyTerminatedError",
}
// IsAlreadyTerminated asserts alreadyTerminatedError. Here we also check for
// the AWS error code IncorrectInstanceState. The AWS errors might look like the
// following example.
//
// IncorrectInstanceState: The instance 'i-0b26c88f3546aefee' must be in a 'running', 'pending', 'stopping' or 'stopped' state for this operation.
func IsAlreadyTerminated(err error) bool {
c := microerror.Cause(err)
aerr, ok := c.(awserr.Error)
if ok {
if aerr.Code() == "IncorrectInstanceState" {
return true
}
}
if c == alreadyTerminatedError {
return true
}
return false
}
var deleteInProgressError = µerror.Error{
Kind: "deleteInProgressError",
}
// IsDeleteInProgress asserts deleteInProgressError.
func IsDeleteInProgress(err error) bool {
c := microerror.Cause(err)
if c == nil {
return false
}
if strings.Contains(c.Error(), cloudformation.ResourceStatusDeleteInProgress) {
return true
}
if c == deleteInProgressError {
return true
}
return false
}
var invalidConfigError = µerror.Error{
Kind: "invalidConfigError",
}
// IsInvalidConfig asserts invalidConfigError.
func IsInvalidConfig(err error) bool {
return microerror.Cause(err) == invalidConfigError
}
var notExistsError = µerror.Error{
Kind: "notExistsError",
}
// IsNotExists asserts notExistsError.
func IsNotExists(err error) bool {
c := microerror.Cause(err)
if c == nil {
return false
}
if strings.Contains(c.Error(), "does not exist") {
return true
}
if c == notExistsError {
return true
}
return false
}
var updateInProgressError = µerror.Error{
Kind: "updateInProgressError",
}
// IsUpdateInProgress asserts updateInProgressError.
func IsUpdateInProgress(err error) bool {
c := microerror.Cause(err)
if c == nil {
return false
}
if strings.Contains(c.Error(), cloudformation.ResourceStatusUpdateInProgress) {
return true
}
if c == updateInProgressError {
return true
}
return false
}
var emptyAmazonAccountIDError = µerror.Error{
Kind: "emptyAmazonAccountIDError",
}
// IsEmptyAmazonAccountID asserts emptyAmazonAccountIDError.
func IsEmptyAmazonAccountID(err error) bool {
return microerror.Cause(err) == emptyAmazonAccountIDError
}
var malformedAmazonAccountIDError = µerror.Error{
Kind: "malformedAmazonAccountIDError",
}
// IsMalformedAmazonAccountID asserts malformedAmazonAccountIDError.
func IsMalformedAmazonAccountID(err error) bool {
return microerror.Cause(err) == malformedAmazonAccountIDError
}
var notFoundError = µerror.Error{
Kind: "notFoundError",
}
// IsNotFound asserts notFoundError
func IsNotFound(err error) bool {
return microerror.Cause(err) == notFoundError
}
var wrongAmazonAccountIDLengthError = µerror.Error{
Kind: "wrongAmazonAccountIDLengthError",
}
// IsWrongAmazonAccountIDLength asserts wrongAmazonAccountIDLengthError.
func IsWrongAmazonAccountIDLength(err error) bool {
return microerror.Cause(err) == wrongAmazonAccountIDLengthError
}
var wrongTypeError = µerror.Error{
Kind: "wrongTypeError",
}
// IsWrongType asserts wrongTypeError.
func IsWrongType(err error) bool {
return microerror.Cause(err) == wrongTypeError
}
var tooFewResultsError = µerror.Error{
Kind: "tooFewResultsError",
}
// IsTooFewResults asserts tooFewResultsError.
func IsTooFewResults(err error) bool {
return microerror.Cause(err) == tooFewResultsError
}
var tooManyResultsError = µerror.Error{
Kind: "tooManyResultsError",
}
// IsTooManyResults asserts tooManyResultsError.
func IsTooManyResults(err error) bool {
return microerror.Cause(err) == tooManyResultsError
}