/
errors.go
229 lines (183 loc) · 6.34 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
package config
import (
"fmt"
"strings"
"github.com/go-spatial/tegola/provider"
)
type ErrMapNotFound struct {
MapName string
}
func (e ErrMapNotFound) Error() string {
return fmt.Sprintf("config: map (%v) not found", e.MapName)
}
type ErrParamTokenReserved struct {
MapName string
Parameter provider.QueryParameter
}
func (e ErrParamTokenReserved) Error() string {
return fmt.Sprintf("config: map %s parameter %s uses a reserved token name %s",
e.MapName, e.Parameter.Name, e.Parameter.Token)
}
type ErrParamDuplicateName struct {
MapName string
Parameter provider.QueryParameter
}
func (e ErrParamDuplicateName) Error() string {
return fmt.Sprintf("config: map %s parameter %s has a name already used by another parameter",
e.MapName, e.Parameter.Name)
}
type ErrParamDuplicateToken struct {
MapName string
Parameter provider.QueryParameter
}
func (e ErrParamDuplicateToken) Error() string {
return fmt.Sprintf("config: map %s parameter %s has a token name %s already used by another parameter",
e.MapName, e.Parameter.Token, e.Parameter.Name)
}
type ErrParamUnknownType struct {
MapName string
Parameter provider.QueryParameter
}
func (e ErrParamUnknownType) Error() string {
validTypes := make([]string, 0, len(provider.ParamTypeDecoders))
for k := range provider.ParamTypeDecoders {
validTypes = append(validTypes, k)
}
return fmt.Sprintf("config: map %s parameter %s has an unknown type %s, must be one of: %s",
e.MapName, e.Parameter.Name, e.Parameter.Type, strings.Join(validTypes, ","))
}
type ErrParamTwoDefaults struct {
MapName string
Parameter provider.QueryParameter
}
func (e ErrParamTwoDefaults) Error() string {
return fmt.Sprintf("config: map %s parameter %s has both default_value and default_sql",
e.MapName, e.Parameter.Name)
}
type ErrParamInvalidDefault struct {
MapName string
Parameter provider.QueryParameter
}
func (e ErrParamInvalidDefault) Error() string {
return fmt.Sprintf("config: map %s parameter %s has a default value that is invalid for type %s",
e.MapName, e.Parameter.Name, e.Parameter.Type)
}
type ErrParamBadTokenName struct {
MapName string
Parameter provider.QueryParameter
}
func (e ErrParamBadTokenName) Error() string {
return fmt.Sprintf("config: map %s parameter %s has an invalid token name %s",
e.MapName, e.Parameter.Name, e.Parameter.Token)
}
type ErrInvalidProviderForMap struct {
MapName string
ProviderName string
}
func (e ErrInvalidProviderForMap) Error() string {
return fmt.Sprintf("config: map %s references unknown provider %s", e.MapName, e.ProviderName)
}
type ErrInvalidProviderLayerName struct {
ProviderLayerName string
}
func (e ErrInvalidProviderLayerName) Error() string {
return fmt.Sprintf("config: invalid provider layer name (%v)", e.ProviderLayerName)
}
type ErrOverlappingLayerZooms struct {
ProviderLayer1 string
ProviderLayer2 string
}
func (e ErrOverlappingLayerZooms) Error() string {
return fmt.Sprintf("config: overlapping zooms for layer (%v) and layer (%v)", e.ProviderLayer1, e.ProviderLayer2)
}
type ErrInvalidLayerZoom struct {
ProviderLayer string
MinZoom bool
Zoom int
ZoomLimit int
}
func (e ErrInvalidLayerZoom) Error() string {
n, d := "MaxZoom", "above"
if e.MinZoom {
n, d = "MinZoom", "below"
}
return fmt.Sprintf(
"config: for provider layer %v %v(%v) is %v allowed level of %v",
e.ProviderLayer, n, e.Zoom, d, e.ZoomLimit,
)
}
// ErrMVTDifferentProviders represents when there are two different MVT providers in a map
// definition. MVT providers have to be unique per map definition
type ErrMVTDifferentProviders struct {
Original string
Current string
}
func (e ErrMVTDifferentProviders) Error() string {
return fmt.Sprintf(
"config: all layer providers need to be the same, first provider is %s second provider is %s",
e.Original,
e.Current,
)
}
// ErrMixedProviders represents the user configuration issue of using an MVT provider with another provider
type ErrMixedProviders struct {
Map string
}
func (e ErrMixedProviders) Error() string {
return fmt.Sprintf("config: can not mix MVT providers with normal providers for map %v", e.Map)
}
// ErrMissingEnvVar represents an environmental variable the system was unable to find in the environment
type ErrMissingEnvVar struct {
EnvVar string
}
func (e ErrMissingEnvVar) Error() string {
return fmt.Sprintf("config: config file is referencing an environment variable that is not set (%v)", e.EnvVar)
}
type ErrInvalidHeader struct {
Header string
}
func (e ErrInvalidHeader) Error() string {
return fmt.Sprintf("config: header (%v) blacklisted", e.Header)
}
type ErrInvalidURIPrefix string
func (e ErrInvalidURIPrefix) Error() string {
return fmt.Sprintf("config: invalid uri_prefix (%v). uri_prefix must start with a forward slash '/' ", string(e))
}
// ErrUnknownProviderType is returned when the config contains a provider type that has not been registered
type ErrUnknownProviderType struct {
Name string // Name is the name of the entry in the config
Type string // Type is the name of the data provider
KnownProviders []string
}
func (e ErrUnknownProviderType) Error() string {
return fmt.Sprintf("config: invalid type (%s) for provider %s; known providers are: %v", e.Name, e.Type, strings.Join(e.KnownProviders, ","))
}
// Is returns whether the error is of type ErrUnknownProviderType, only checking the Type value.
func (e ErrUnknownProviderType) Is(err error) bool {
err1, ok := err.(ErrUnknownProviderType)
if !ok {
return false
}
return err1.Type == e.Type
}
// ErrProviderNameRequired is returned when the name of a provider is missing from the provider list
type ErrProviderNameRequired struct {
Pos int
}
func (e ErrProviderNameRequired) Error() string {
return fmt.Sprintf("config: name field required for provider at position %v", e.Pos)
}
// ErrProviderNameDuplicate is returned when the name of a provider is duplicated in the provider list
type ErrProviderNameDuplicate struct {
Pos int
}
func (e ErrProviderNameDuplicate) Error() string {
return fmt.Sprintf("config: name for provider at position %v is a duplicate", e.Pos)
}
// ErrProviderTypeRequired is returned when the type of a provider is missing from the provider list
type ErrProviderTypeRequired struct {
Pos int
}
func (e ErrProviderTypeRequired) Error() string {
return fmt.Sprintf("config: type field required for provider at position %v", e.Pos)
}