Uh oh!
There was an error while loading. Please reload this page.
forked from gophercloud/gophercloud
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
Latest commit
351 lines (282 loc) · 11.1 KB
/
Copy patherrors.go
File metadata and controls
351 lines (282 loc) · 11.1 KB
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package gophercloud
import (
"bytes"
"errors"
"fmt"
"net/http"
"strings"
)
// BaseError is an error type that all other error types embed.
typeBaseErrorstruct {
DefaultErrStringstring
Infostring
}
func (eBaseError) Error() string {
e.DefaultErrString="An error occurred while executing a Gophercloud request."
returne.choseErrString()
}
func (eBaseError) choseErrString() string {
ife.Info!="" {
returne.Info
}
returne.DefaultErrString
}
// ErrMissingInput is the error when input is required in a particular
// situation but not provided by the user
typeErrMissingInputstruct {
BaseError
Argumentstring
}
func (eErrMissingInput) Error() string {
e.DefaultErrString=fmt.Sprintf("Missing input for argument [%s]", e.Argument)
returne.choseErrString()
}
// ErrInvalidInput is an error type used for most non-HTTP Gophercloud errors.
typeErrInvalidInputstruct {
ErrMissingInput
Valueany
}
func (eErrInvalidInput) Error() string {
e.DefaultErrString=fmt.Sprintf("Invalid input provided for argument [%s]: [%+v]", e.Argument, e.Value)
returne.choseErrString()
}
// ErrMissingEnvironmentVariable is the error when environment variable is required
// in a particular situation but not provided by the user
typeErrMissingEnvironmentVariablestruct {
BaseError
EnvironmentVariablestring
}
func (eErrMissingEnvironmentVariable) Error() string {
e.DefaultErrString=fmt.Sprintf("Missing environment variable [%s]", e.EnvironmentVariable)
returne.choseErrString()
}
// ErrMissingAnyoneOfEnvironmentVariables is the error when anyone of the environment variables
// is required in a particular situation but not provided by the user
typeErrMissingAnyoneOfEnvironmentVariablesstruct {
BaseError
EnvironmentVariables []string
}
func (eErrMissingAnyoneOfEnvironmentVariables) Error() string {
e.DefaultErrString=fmt.Sprintf(
"Missing one of the following environment variables [%s]",
strings.Join(e.EnvironmentVariables, ", "),
)
returne.choseErrString()
}
// ErrUnexpectedResponseCode is returned by the Request method when a response code other than
// those listed in OkCodes is encountered.
typeErrUnexpectedResponseCodestruct {
BaseError
URLstring
Methodstring
Expected []int
Actualint
Body []byte
ResponseHeader http.Header
}
func (eErrUnexpectedResponseCode) Error() string {
e.DefaultErrString=fmt.Sprintf(
"Expected HTTP response code %v when accessing [%s %s], but got %d instead: %s",
e.Expected, e.Method, e.URL, e.Actual, bytes.TrimSpace(e.Body),
)
returne.choseErrString()
}
// GetStatusCode returns the actual status code of the error.
func (eErrUnexpectedResponseCode) GetStatusCode() int {
returne.Actual
}
// ResponseCodeIs returns true if this error is or contains an ErrUnexpectedResponseCode reporting
// that the request failed with the given response code. For example, this checks if a request
// failed because of a 404 error:
//
// allServers, err := servers.List(client, servers.ListOpts{})
// if gophercloud.ResponseCodeIs(err, http.StatusNotFound) {
// handleNotFound()
// }
//
// It is safe to pass a nil error, in which case this function always returns false.
funcResponseCodeIs(errerror, statusint) bool {
varcodeErrorErrUnexpectedResponseCode
iferrors.As(err, &codeError) {
returncodeError.Actual==status
}
returnfalse
}
// ErrTimeOut is the error type returned when an operations times out.
typeErrTimeOutstruct {
BaseError
}
func (eErrTimeOut) Error() string {
e.DefaultErrString="A time out occurred"
returne.choseErrString()
}
// ErrUnableToReauthenticate is the error type returned when reauthentication fails.
typeErrUnableToReauthenticatestruct {
BaseError
ErrOriginalerror
ErrReautherror
}
func (eErrUnableToReauthenticate) Error() string {
e.DefaultErrString=fmt.Sprintf("Unable to re-authenticate: %s: %s", e.ErrOriginal, e.ErrReauth)
returne.choseErrString()
}
// ErrErrorAfterReauthentication is the error type returned when reauthentication
// succeeds, but an error occurs afterword (usually an HTTP error).
typeErrErrorAfterReauthenticationstruct {
BaseError
ErrOriginalerror
}
func (eErrErrorAfterReauthentication) Error() string {
e.DefaultErrString=fmt.Sprintf("Successfully re-authenticated, but got error executing request: %s", e.ErrOriginal)
returne.choseErrString()
}
// ErrServiceNotFound is returned when no service in a service catalog matches
// the provided EndpointOpts. This is generally returned by provider service
// factory methods like "NewComputeV2()" and can mean that a service is not
// enabled for your account.
typeErrServiceNotFoundstruct {
BaseError
}
func (eErrServiceNotFound) Error() string {
e.DefaultErrString="No suitable service could be found in the service catalog."
returne.choseErrString()
}
// ErrEndpointNotFound is returned when no available endpoints match the
// provided EndpointOpts. This is also generally returned by provider service
// factory methods, and usually indicates that a region was specified
// incorrectly.
typeErrEndpointNotFoundstruct {
BaseError
}
func (eErrEndpointNotFound) Error() string {
e.DefaultErrString="No suitable endpoint could be found in the service catalog."
returne.choseErrString()
}
// ErrResourceNotFound is the error when trying to retrieve a resource's
// ID by name and the resource doesn't exist.
typeErrResourceNotFoundstruct {
BaseError
Namestring
ResourceTypestring
}
func (eErrResourceNotFound) Error() string {
e.DefaultErrString=fmt.Sprintf("Unable to find %s with name %s", e.ResourceType, e.Name)
returne.choseErrString()
}
// ErrMultipleResourcesFound is the error when trying to retrieve a resource's
// ID by name and multiple resources have the user-provided name.
typeErrMultipleResourcesFoundstruct {
BaseError
Namestring
Countint
ResourceTypestring
}
func (eErrMultipleResourcesFound) Error() string {
e.DefaultErrString=fmt.Sprintf("Found %d %ss matching %s", e.Count, e.ResourceType, e.Name)
returne.choseErrString()
}
// ErrUnexpectedType is the error when an unexpected type is encountered
typeErrUnexpectedTypestruct {
BaseError
Expectedstring
Actualstring
}
func (eErrUnexpectedType) Error() string {
e.DefaultErrString=fmt.Sprintf("Expected %s but got %s", e.Expected, e.Actual)
returne.choseErrString()
}
funcunacceptedAttributeErr(attributestring) string {
returnfmt.Sprintf("The base Identity V3 API does not accept authentication by %s", attribute)
}
funcredundantWithTokenErr(attributestring) string {
returnfmt.Sprintf("%s may not be provided when authenticating with a TokenID", attribute)
}
funcredundantWithUserID(attributestring) string {
returnfmt.Sprintf("%s may not be provided when authenticating with a UserID", attribute)
}
// ErrAPIKeyProvided indicates that an APIKey was provided but can't be used.
typeErrAPIKeyProvidedstruct{ BaseError }
func (eErrAPIKeyProvided) Error() string {
returnunacceptedAttributeErr("APIKey")
}
// ErrTenantIDProvided indicates that a TenantID was provided but can't be used.
typeErrTenantIDProvidedstruct{ BaseError }
func (eErrTenantIDProvided) Error() string {
returnunacceptedAttributeErr("TenantID")
}
// ErrTenantNameProvided indicates that a TenantName was provided but can't be used.
typeErrTenantNameProvidedstruct{ BaseError }
func (eErrTenantNameProvided) Error() string {
returnunacceptedAttributeErr("TenantName")
}
// ErrUsernameWithToken indicates that a Username was provided, but token authentication is being used instead.
typeErrUsernameWithTokenstruct{ BaseError }
func (eErrUsernameWithToken) Error() string {
returnredundantWithTokenErr("Username")
}
// ErrUserIDWithToken indicates that a UserID was provided, but token authentication is being used instead.
typeErrUserIDWithTokenstruct{ BaseError }
func (eErrUserIDWithToken) Error() string {
returnredundantWithTokenErr("UserID")
}
// ErrDomainIDWithToken indicates that a DomainID was provided, but token authentication is being used instead.
typeErrDomainIDWithTokenstruct{ BaseError }
func (eErrDomainIDWithToken) Error() string {
returnredundantWithTokenErr("DomainID")
}
// ErrDomainNameWithToken indicates that a DomainName was provided, but token authentication is being used instead.s
typeErrDomainNameWithTokenstruct{ BaseError }
func (eErrDomainNameWithToken) Error() string {
returnredundantWithTokenErr("DomainName")
}
// ErrUsernameOrUserID indicates that neither username nor userID are specified, or both are at once.
typeErrUsernameOrUserIDstruct{ BaseError }
func (eErrUsernameOrUserID) Error() string {
return"Exactly one of Username and UserID must be provided for password authentication"
}
// ErrDomainIDWithUserID indicates that a DomainID was provided, but unnecessary because a UserID is being used.
typeErrDomainIDWithUserIDstruct{ BaseError }
func (eErrDomainIDWithUserID) Error() string {
returnredundantWithUserID("DomainID")
}
// ErrDomainNameWithUserID indicates that a DomainName was provided, but unnecessary because a UserID is being used.
typeErrDomainNameWithUserIDstruct{ BaseError }
func (eErrDomainNameWithUserID) Error() string {
returnredundantWithUserID("DomainName")
}
// ErrDomainIDOrDomainName indicates that a username was provided, but no domain to scope it.
// It may also indicate that both a DomainID and a DomainName were provided at once.
typeErrDomainIDOrDomainNamestruct{ BaseError }
func (eErrDomainIDOrDomainName) Error() string {
return"You must provide exactly one of DomainID or DomainName to authenticate by Username"
}
// ErrMissingPassword indicates that no password was provided and no token is available.
typeErrMissingPasswordstruct{ BaseError }
func (eErrMissingPassword) Error() string {
return"You must provide a password to authenticate"
}
// ErrScopeDomainIDOrDomainName indicates that a domain ID or Name was required in a Scope, but not present.
typeErrScopeDomainIDOrDomainNamestruct{ BaseError }
func (eErrScopeDomainIDOrDomainName) Error() string {
return"You must provide exactly one of DomainID or DomainName in a Scope with ProjectName"
}
// ErrScopeProjectIDOrProjectName indicates that both a ProjectID and a ProjectName were provided in a Scope.
typeErrScopeProjectIDOrProjectNamestruct{ BaseError }
func (eErrScopeProjectIDOrProjectName) Error() string {
return"You must provide at most one of ProjectID or ProjectName in a Scope"
}
// ErrScopeProjectIDAlone indicates that a ProjectID was provided with other constraints in a Scope.
typeErrScopeProjectIDAlonestruct{ BaseError }
func (eErrScopeProjectIDAlone) Error() string {
return"ProjectID must be supplied alone in a Scope"
}
// ErrScopeEmpty indicates that no credentials were provided in a Scope.
typeErrScopeEmptystruct{ BaseError }
func (eErrScopeEmpty) Error() string {
return"You must provide either a Project or Domain in a Scope"
}
// ErrAppCredMissingSecret indicates that no Application Credential Secret was provided with Application Credential ID or Name
typeErrAppCredMissingSecretstruct{ BaseError }
func (eErrAppCredMissingSecret) Error() string {
return"You must provide an Application Credential Secret"
}