-
Notifications
You must be signed in to change notification settings - Fork 22
/
error.go
59 lines (47 loc) · 1.52 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
package drainerinitializer
import (
"regexp"
"github.com/giantswarm/microerror"
)
var (
// noActiveLifeCycleActionRegExp is a fuzzy regular expression to match
// Autoscaling errors which we have to string match due to the lack of proper
// error types in the AWS SDK.
noActiveLifeCycleActionRegExp = regexp.MustCompile(`(?im)no.*life.*cycle.*found`)
)
// 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",
}
var invalidConfigError = µerror.Error{
Kind: "invalidConfigError",
}
// IsInvalidConfig asserts invalidConfigError.
func IsInvalidConfig(err error) bool {
return microerror.Cause(err) == invalidConfigError
}
var noActiveLifeCycleActionError = µerror.Error{
Kind: "noActiveLifeCycleActionError",
}
// IsNoActiveLifeCycleAction asserts noActiveLifeCycleActionError. It also
// checks for some string matching in the error message to figure if the AWS API
// gives the error we expect.
func IsNoActiveLifeCycleAction(err error) bool {
c := microerror.Cause(err)
if c == nil {
return false
}
if noActiveLifeCycleActionRegExp.MatchString(c.Error()) {
return true
}
if c == noActiveLifeCycleActionError {
return true
}
return false
}