/
errors.go
261 lines (212 loc) · 8.6 KB
/
errors.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package manifest
import (
"fmt"
"strconv"
"strings"
"github.com/aws/copilot-cli/internal/pkg/aws/cloudfront"
"github.com/aws/copilot-cli/internal/pkg/template"
"github.com/dustin/go-humanize/english"
)
// ErrInvalidWorkloadType occurs when a user requested a manifest template type that doesn't exist.
type ErrInvalidWorkloadType struct {
Type string
}
func (e *ErrInvalidWorkloadType) Error() string {
return fmt.Sprintf("invalid manifest type: %s", e.Type)
}
// ErrInvalidPipelineManifestVersion occurs when the pipeline.yml/manifest.yml file
// contains invalid schema version during unmarshalling.
type ErrInvalidPipelineManifestVersion struct {
invalidVersion PipelineSchemaMajorVersion
}
func (e *ErrInvalidPipelineManifestVersion) Error() string {
return fmt.Sprintf("pipeline manifest contains invalid schema version: %d", e.invalidVersion)
}
// Is compares the 2 errors. Only returns true if the errors are of the same
// type and contain the same information.
func (e *ErrInvalidPipelineManifestVersion) Is(target error) bool {
t, ok := target.(*ErrInvalidPipelineManifestVersion)
return ok && t.invalidVersion == e.invalidVersion
}
// ErrUnknownProvider occurs CreateProvider() is called with configurations
// that do not map to any supported provider.
type ErrUnknownProvider struct {
unknownProviderProperties interface{}
}
func (e *ErrUnknownProvider) Error() string {
return fmt.Sprintf("no provider found for properties: %v",
e.unknownProviderProperties)
}
// Is compares the 2 errors. Returns true if the errors are of the same
// type
func (e *ErrUnknownProvider) Is(target error) bool {
_, ok := target.(*ErrUnknownProvider)
return ok
}
type errFieldMustBeSpecified struct {
missingField string
conditionalFields []string
allMustBeSpecified bool
}
func (e *errFieldMustBeSpecified) Error() string {
errMsg := fmt.Sprintf(`%q must be specified`, e.missingField)
if len(e.conditionalFields) == 0 {
return errMsg
}
conjunction := "or"
if e.allMustBeSpecified {
conjunction = "and"
}
return fmt.Sprintf(`%s if %s %s specified`, errMsg, english.WordSeries(quoteStringSlice(e.conditionalFields), conjunction),
english.PluralWord(len(e.conditionalFields), "is", "are"))
}
type errInvalidAutoscalingFieldsWithWkldType struct {
invalidFields []string
workloadType string
}
func (e *errInvalidAutoscalingFieldsWithWkldType) Error() string {
return fmt.Sprintf("autoscaling %v %v %v invalid with workload type %v", english.PluralWord(len(e.invalidFields), "field", "fields"),
english.WordSeries(template.QuoteSliceFunc(e.invalidFields), "and"), english.PluralWord(len(e.invalidFields), "is", "are"), e.workloadType)
}
type errFieldMutualExclusive struct {
firstField string
secondField string
mustExist bool
}
func (e *errFieldMutualExclusive) Error() string {
if e.mustExist {
return fmt.Sprintf(`must specify one of "%s" and "%s"`, e.firstField, e.secondField)
}
return fmt.Sprintf(`must specify one, not both, of "%s" and "%s"`, e.firstField, e.secondField)
}
type errGracePeriodsInBothALBAndNLB struct {
errFieldMutualExclusive
}
func (e *errGracePeriodsInBothALBAndNLB) RecommendedActions() string {
return `"grace_period" is a configuration shared by "http" and "nlb". Specify it only once under either "http" or "nlb".`
}
type errGracePeriodSpecifiedInAdditionalListener struct {
index int
}
func (e *errGracePeriodSpecifiedInAdditionalListener) Error() string {
return fmt.Sprintf(`"grace_period" specified for "nlb.additional_listeners[%d]"`, e.index)
}
// RecommendActions returns recommended actions to be taken after the error.
func (e *errGracePeriodSpecifiedInAdditionalListener) RecommendActions() string {
return fmt.Sprintf(`Instead of under "nlb.additional_listeners[%d].healthcheck", specify "grace_period" under the top-level "nlb.healthcheck".`, e.index)
}
type errGracePeriodSpecifiedInAdditionalRule struct {
index int
}
func (e *errGracePeriodSpecifiedInAdditionalRule) Error() string {
return fmt.Sprintf(`"grace_period" specified for "http.additional_rules[%d]"`, e.index)
}
// RecommendActions returns recommended actions to be taken after the error.
func (e *errGracePeriodSpecifiedInAdditionalRule) RecommendActions() string {
return fmt.Sprintf(`Instead of under "http.additional_rules[%d].healthcheck", specify "grace_period" under the top-level "http.healthcheck".`, e.index)
}
type errSpecifiedBothIngressFields struct {
firstField string
secondField string
}
func (e *errSpecifiedBothIngressFields) Error() string {
return fmt.Sprintf(`must specify one, not both, of "%s" and "%s"`, e.firstField, e.secondField)
}
// RecommendActions returns recommended actions to be taken after the error.
func (e *errSpecifiedBothIngressFields) RecommendActions() string {
privateOrPublicField := strings.Split(e.firstField, ".")[0]
if privateOrPublicField == "public" {
return `
It looks like you specified ingress under both "http.public.security_groups.ingress" and "http.public.ingress".
After Copilot v1.23.0, we have deprecated "http.public.security_groups.ingress" in favor of "http.public.ingress".
This means that "http.public.security_groups.ingress.cdn" is removed in favor of "http.public.ingress.cdn".
With the new release manifest configuration for cdn looks like:
http:
public:
ingress:
cdn: true
`
}
return `
It looks like you specified ingress under both "http.private.security_groups.ingress" and "http.private.ingress".
After Copilot v1.23.0, we have deprecated "http.private.security_groups.ingress" in favor of "http.private.ingress".
This means that "http.private.security_groups.ingress.from_vpc" is removed in favor of "http.private.ingress.vpc".
With the new release manifest configuration for vpc looks like:
http:
private:
ingress:
vpc: true
`
}
type errRangeValueLessThanZero struct {
min int
max int
spotFrom int
}
func (e *errRangeValueLessThanZero) Error() string {
return fmt.Sprintf("min value %d, max value %d, and spot_from value %d must all be positive", e.min, e.max, e.spotFrom)
}
type errMinGreaterThanMax struct {
min int
max int
}
func (e *errMinGreaterThanMax) Error() string {
return fmt.Sprintf("min value %d cannot be greater than max value %d", e.min, e.max)
}
type errAtLeastOneFieldMustBeSpecified struct {
missingFields []string
conditionalField string
}
func (e *errAtLeastOneFieldMustBeSpecified) Error() string {
errMsg := fmt.Sprintf("must specify at least one of %s", english.WordSeries(quoteStringSlice(e.missingFields), "or"))
if e.conditionalField != "" {
errMsg = fmt.Sprintf(`%s if "%s" is specified`, errMsg, e.conditionalField)
}
return errMsg
}
type errInvalidCloudFrontRegion struct{}
func (e *errInvalidCloudFrontRegion) Error() string {
return fmt.Sprintf(`cdn certificate must be in region %s`, cloudfront.CertRegion)
}
// RecommendActions returns recommended actions to be taken after the error.
func (e *errInvalidCloudFrontRegion) RecommendActions() string {
return fmt.Sprintf(`It looks like your CloudFront certificate is in the wrong region. CloudFront only supports certificates in %s.
We recommend creating a duplicate certificate in the %s region through AWS Certificate Manager.
More information: https://go.aws/3BMxY4J`, cloudfront.CertRegion, cloudfront.CertRegion)
}
func quoteStringSlice(in []string) []string {
quoted := make([]string, len(in))
for idx, str := range in {
quoted[idx] = strconv.Quote(str)
}
return quoted
}
type errContainersExposingSamePort struct {
firstContainer string
secondContainer string
port uint16
}
func (e *errContainersExposingSamePort) Error() string {
return fmt.Sprintf(`containers %q and %q are exposing the same port %d`, e.firstContainer, e.secondContainer, e.port)
}
type errContainerPortExposedWithMultipleProtocol struct {
container string
port uint16
firstProtocol string
secondProtocol string
}
func (e *errContainerPortExposedWithMultipleProtocol) Error() string {
return fmt.Sprintf(`container %q is exposing the same port %d with protocol %s and %s`, e.container, e.port, e.firstProtocol, e.secondProtocol)
}
type errHealthCheckPortExposedWithInvalidProtocol struct {
healthCheckPort uint16
container string
protocol string
}
func (e *errHealthCheckPortExposedWithInvalidProtocol) Error() string {
return fmt.Sprintf(`container %q exposes port %d using protocol %s invalid for health checks. Valid protocol %s %s.`,
e.container, e.healthCheckPort, e.protocol, english.PluralWord(len(validHealthCheckProtocols), "is", "are"),
english.WordSeries(quoteStringSlice(validHealthCheckProtocols), "or"))
}