This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
/
error.go
197 lines (164 loc) · 6.14 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
package userconfig
import (
"encoding/json"
"github.com/juju/errgo"
)
var (
UnknownJSONFieldError = errgo.New("unknown JSON field")
MissingJSONFieldError = errgo.New("missing JSON field")
InvalidSizeError = errgo.New("invalid size")
DuplicateVolumePathError = errgo.New("duplicate volume path")
InvalidEnvListFormatError = errgo.Newf("unable to parse 'env', objects or Array of strings expected")
CrossServicePodError = errgo.New("pod is used in different services")
PodUsedOnlyOnceError = errgo.New("pod is used in only 1 component")
InvalidVolumeConfigError = errgo.New("invalid volume configuration")
InvalidDependencyConfigError = errgo.New("invalid dependency configuration")
InvalidScalingConfigError = errgo.New("invalid scaling configuration")
InvalidPortConfigError = errgo.New("Invalid port configuration")
InvalidDomainDefinitionError = errgo.New("invalid domain definition")
InvalidLinkDefinitionError = errgo.New("invalid link definition")
InvalidAppDefinitionError = errgo.New("invalid service definition")
InvalidComponentDefinitionError = errgo.New("invalid component definition")
InvalidImageDefinitionError = errgo.New("invalid image definition")
InvalidServiceNameError = errgo.New("invalid service name")
InvalidComponentNameError = errgo.New("invalid component name")
InvalidPodConfigError = errgo.New("invalid pod configuration")
PortNotFoundError = errgo.New("port not found")
ComponentNotFoundError = errgo.New("component not found")
InternalError = errgo.New("internal error")
MissingValidationContextError = errgo.New("missing validation context")
InvalidArgumentError = errgo.New("invalid argument")
VolumeCycleError = errgo.New("cycle detected in volume configuration")
WrongDiffOrderError = errgo.New("wrong diff order")
LinkCycleError = errgo.New("cycle detected in link definition")
InvalidMemoryLimitError = errgo.New("Invalid 'memory-limit' field")
mask = errgo.MaskFunc(IsInvalidEnvListFormat,
IsUnknownJsonField,
IsMissingJsonField,
IsInvalidSize,
IsDuplicateVolumePath,
IsCrossServicePod,
IsPodUsedOnlyOnce,
IsInvalidVolumeConfig,
IsVolumeCycle,
IsInvalidDependencyConfig,
IsInvalidScalingConfig,
IsInvalidPortConfig,
IsInvalidPodConfig,
IsInvalidDomainDefinition,
IsInvalidLinkDefinition,
IsInvalidAppDefinition,
IsInvalidComponentDefinition,
IsInvalidImageDefinition,
IsInvalidServiceName,
IsInvalidComponentName,
IsComponentNotFound,
IsPortNotFound,
IsInternal,
IsMissingValidationContext,
IsInvalidArgument,
IsSyntax,
IsLinkCycle,
IsInvalidMemoryLimitError,
)
maskAny = errgo.MaskFunc(errgo.Any)
)
// maskf is short for mask(errgo.WithCausef(nil, cause, f, a...))
func maskf(cause error, f string, a ...interface{}) error {
err := mask(errgo.WithCausef(nil, cause, f, a...))
// the above call with set this location instead of that of our caller.
// that is fixed below.
if e, _ := err.(*errgo.Err); e != nil {
e.SetLocation(1)
}
return err
}
func IsInvalidMemoryLimitError(err error) bool {
return errgo.Cause(err) == InvalidMemoryLimitError
}
func IsUnknownJsonField(err error) bool {
return errgo.Cause(err) == UnknownJSONFieldError
}
func IsMissingJsonField(err error) bool {
return errgo.Cause(err) == MissingJSONFieldError
}
func IsInvalidSize(err error) bool {
return errgo.Cause(err) == InvalidSizeError
}
func IsDuplicateVolumePath(err error) bool {
return errgo.Cause(err) == DuplicateVolumePathError
}
func IsInvalidEnvListFormat(err error) bool {
return errgo.Cause(err) == InvalidEnvListFormatError
}
func IsCrossServicePod(err error) bool {
return errgo.Cause(err) == CrossServicePodError
}
func IsPodUsedOnlyOnce(err error) bool {
return errgo.Cause(err) == PodUsedOnlyOnceError
}
// IsInvalidVolumeConfig returns true if the given error is of type
// InvalidVolumeConfigError, VolumeCycleError or DuplicateVolumePathError. False otherwise.
func IsInvalidVolumeConfig(err error) bool {
cause := errgo.Cause(err)
return cause == InvalidVolumeConfigError || cause == DuplicateVolumePathError || cause == VolumeCycleError
}
func IsVolumeCycle(err error) bool {
return errgo.Cause(err) == VolumeCycleError
}
func IsInvalidDependencyConfig(err error) bool {
return errgo.Cause(err) == InvalidDependencyConfigError
}
func IsInvalidScalingConfig(err error) bool {
return errgo.Cause(err) == InvalidScalingConfigError
}
func IsInvalidPodConfig(err error) bool {
return errgo.Cause(err) == InvalidPodConfigError
}
func IsInvalidPortConfig(err error) bool {
return errgo.Cause(err) == InvalidPortConfigError
}
func IsInvalidDomainDefinition(err error) bool {
return errgo.Cause(err) == InvalidDomainDefinitionError
}
func IsInvalidLinkDefinition(err error) bool {
return errgo.Cause(err) == InvalidLinkDefinitionError
}
func IsInvalidAppDefinition(err error) bool {
return errgo.Cause(err) == InvalidAppDefinitionError
}
func IsInvalidComponentDefinition(err error) bool {
return errgo.Cause(err) == InvalidComponentDefinitionError
}
func IsInvalidImageDefinition(err error) bool {
return errgo.Cause(err) == InvalidImageDefinitionError
}
func IsInvalidServiceName(err error) bool {
return errgo.Cause(err) == InvalidServiceNameError
}
func IsInvalidComponentName(err error) bool {
return errgo.Cause(err) == InvalidComponentNameError
}
func IsComponentNotFound(err error) bool {
return errgo.Cause(err) == ComponentNotFoundError
}
func IsPortNotFound(err error) bool {
return errgo.Cause(err) == PortNotFoundError
}
func IsInternal(err error) bool {
return errgo.Cause(err) == InternalError
}
func IsMissingValidationContext(err error) bool {
return errgo.Cause(err) == MissingValidationContextError
}
func IsInvalidArgument(err error) bool {
return errgo.Cause(err) == InvalidArgumentError
}
func IsLinkCycle(err error) bool {
return errgo.Cause(err) == LinkCycleError
}
// IsSyntax returns true if the cause of the given error in a json.SyntaxError
func IsSyntax(err error) bool {
_, ok := errgo.Cause(err).(*json.SyntaxError)
return ok
}