/
error.go
160 lines (124 loc) · 3.71 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
package tccpn
import (
"fmt"
"strings"
"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 nodes cloud formation stack has stack status %#q", cloudformation.StackStatusCreateFailed),
}
var eventCFUpdateRollbackError = µerror.Error{
Kind: "CFUpdateRollbackFailed",
Desc: fmt.Sprintf("The tenant cluster's control plane nodes cloud formation stack has stack status %#q", cloudformation.StackStatusUpdateRollbackFailed),
}
var eventCFRollbackError = µerror.Error{
Kind: "CFRollbackFailed",
Desc: fmt.Sprintf("The tenant cluster's control plane nodes cloud formation stack has stack status %#q", cloudformation.StackStatusRollbackFailed),
}
var eventCFDeleteError = µerror.Error{
Kind: "CFDeleteFailed",
Desc: fmt.Sprintf("The tenant cluster's control plane nodes 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 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 notFoundError = µerror.Error{
Kind: "notFoundError",
}
// IsNotFound asserts notFoundError.
func IsNotFound(err error) bool {
return microerror.Cause(err) == notFoundError
}
var tooManyCRsError = µerror.Error{
Kind: "tooManyCRsError",
Desc: "There is only a single AWSCluster CR allowed with the current implementation.",
}
// IsTooManyCRsError asserts tooManyCRsError.
func IsTooManyCRsError(err error) bool {
return microerror.Cause(err) == tooManyCRsError
}
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 emptyDataError = µerror.Error{
Kind: "emtpyDataError",
}