8 // BaseError is an error type that all other error types embed.
9 type BaseError struct {
10 DefaultErrString string
14 func (e BaseError) Error() string {
15 e.DefaultErrString = "An error occurred while executing a Gophercloud request."
16 return e.choseErrString()
19 func (e BaseError) choseErrString() string {
23 return e.DefaultErrString
26 // ErrMissingInput is the error when input is required in a particular
27 // situation but not provided by the user
28 type ErrMissingInput struct {
33 func (e ErrMissingInput) Error() string {
34 e.DefaultErrString = fmt.Sprintf("Missing input for argument [%s]", e.Argument)
35 return e.choseErrString()
38 // ErrInvalidInput is an error type used for most non-HTTP Gophercloud errors.
39 type ErrInvalidInput struct {
44 func (e ErrInvalidInput) Error() string {
45 e.DefaultErrString = fmt.Sprintf("Invalid input provided for argument [%s]: [%+v]", e.Argument, e.Value)
46 return e.choseErrString()
49 // ErrMissingEnvironmentVariable is the error when environment variable is required
50 // in a particular situation but not provided by the user
51 type ErrMissingEnvironmentVariable struct {
53 EnvironmentVariable string
56 func (e ErrMissingEnvironmentVariable) Error() string {
57 e.DefaultErrString = fmt.Sprintf("Missing environment variable [%s]", e.EnvironmentVariable)
58 return e.choseErrString()
61 // ErrMissingAnyoneOfEnvironmentVariables is the error when anyone of the environment variables
62 // is required in a particular situation but not provided by the user
63 type ErrMissingAnyoneOfEnvironmentVariables struct {
65 EnvironmentVariables []string
68 func (e ErrMissingAnyoneOfEnvironmentVariables) Error() string {
69 e.DefaultErrString = fmt.Sprintf(
70 "Missing one of the following environment variables [%s]",
71 strings.Join(e.EnvironmentVariables, ", "),
73 return e.choseErrString()
76 // ErrUnexpectedResponseCode is returned by the Request method when a response code other than
77 // those listed in OkCodes is encountered.
78 type ErrUnexpectedResponseCode struct {
87 func (e ErrUnexpectedResponseCode) Error() string {
88 e.DefaultErrString = fmt.Sprintf(
89 "Expected HTTP response code %v when accessing [%s %s], but got %d instead\n%s",
90 e.Expected, e.Method, e.URL, e.Actual, e.Body,
92 return e.choseErrString()
95 // ErrDefault400 is the default error type returned on a 400 HTTP response code.
96 type ErrDefault400 struct {
97 ErrUnexpectedResponseCode
100 // ErrDefault401 is the default error type returned on a 401 HTTP response code.
101 type ErrDefault401 struct {
102 ErrUnexpectedResponseCode
105 // ErrDefault403 is the default error type returned on a 403 HTTP response code.
106 type ErrDefault403 struct {
107 ErrUnexpectedResponseCode
110 // ErrDefault404 is the default error type returned on a 404 HTTP response code.
111 type ErrDefault404 struct {
112 ErrUnexpectedResponseCode
115 // ErrDefault405 is the default error type returned on a 405 HTTP response code.
116 type ErrDefault405 struct {
117 ErrUnexpectedResponseCode
120 // ErrDefault408 is the default error type returned on a 408 HTTP response code.
121 type ErrDefault408 struct {
122 ErrUnexpectedResponseCode
125 // ErrDefault409 is the default error type returned on a 409 HTTP response code.
126 type ErrDefault409 struct {
127 ErrUnexpectedResponseCode
130 // ErrDefault429 is the default error type returned on a 429 HTTP response code.
131 type ErrDefault429 struct {
132 ErrUnexpectedResponseCode
135 // ErrDefault500 is the default error type returned on a 500 HTTP response code.
136 type ErrDefault500 struct {
137 ErrUnexpectedResponseCode
140 // ErrDefault503 is the default error type returned on a 503 HTTP response code.
141 type ErrDefault503 struct {
142 ErrUnexpectedResponseCode
145 func (e ErrDefault400) Error() string {
146 e.DefaultErrString = fmt.Sprintf(
147 "Bad request with: [%s %s], error message: %s",
148 e.Method, e.URL, e.Body,
150 return e.choseErrString()
152 func (e ErrDefault401) Error() string {
153 return "Authentication failed"
155 func (e ErrDefault403) Error() string {
156 e.DefaultErrString = fmt.Sprintf(
157 "Request forbidden: [%s %s], error message: %s",
158 e.Method, e.URL, e.Body,
160 return e.choseErrString()
162 func (e ErrDefault404) Error() string {
163 return "Resource not found"
165 func (e ErrDefault405) Error() string {
166 return "Method not allowed"
168 func (e ErrDefault408) Error() string {
169 return "The server timed out waiting for the request"
171 func (e ErrDefault429) Error() string {
172 return "Too many requests have been sent in a given amount of time. Pause" +
173 " requests, wait up to one minute, and try again."
175 func (e ErrDefault500) Error() string {
176 return "Internal Server Error"
178 func (e ErrDefault503) Error() string {
179 return "The service is currently unable to handle the request due to a temporary" +
180 " overloading or maintenance. This is a temporary condition. Try again later."
183 // Err400er is the interface resource error types implement to override the error message
185 type Err400er interface {
186 Error400(ErrUnexpectedResponseCode) error
189 // Err401er is the interface resource error types implement to override the error message
191 type Err401er interface {
192 Error401(ErrUnexpectedResponseCode) error
195 // Err403er is the interface resource error types implement to override the error message
197 type Err403er interface {
198 Error403(ErrUnexpectedResponseCode) error
201 // Err404er is the interface resource error types implement to override the error message
203 type Err404er interface {
204 Error404(ErrUnexpectedResponseCode) error
207 // Err405er is the interface resource error types implement to override the error message
209 type Err405er interface {
210 Error405(ErrUnexpectedResponseCode) error
213 // Err408er is the interface resource error types implement to override the error message
215 type Err408er interface {
216 Error408(ErrUnexpectedResponseCode) error
219 // Err409er is the interface resource error types implement to override the error message
221 type Err409er interface {
222 Error409(ErrUnexpectedResponseCode) error
225 // Err429er is the interface resource error types implement to override the error message
227 type Err429er interface {
228 Error429(ErrUnexpectedResponseCode) error
231 // Err500er is the interface resource error types implement to override the error message
233 type Err500er interface {
234 Error500(ErrUnexpectedResponseCode) error
237 // Err503er is the interface resource error types implement to override the error message
239 type Err503er interface {
240 Error503(ErrUnexpectedResponseCode) error
243 // ErrTimeOut is the error type returned when an operations times out.
244 type ErrTimeOut struct {
248 func (e ErrTimeOut) Error() string {
249 e.DefaultErrString = "A time out occurred"
250 return e.choseErrString()
253 // ErrUnableToReauthenticate is the error type returned when reauthentication fails.
254 type ErrUnableToReauthenticate struct {
259 func (e ErrUnableToReauthenticate) Error() string {
260 e.DefaultErrString = fmt.Sprintf("Unable to re-authenticate: %s", e.ErrOriginal)
261 return e.choseErrString()
264 // ErrErrorAfterReauthentication is the error type returned when reauthentication
265 // succeeds, but an error occurs afterword (usually an HTTP error).
266 type ErrErrorAfterReauthentication struct {
271 func (e ErrErrorAfterReauthentication) Error() string {
272 e.DefaultErrString = fmt.Sprintf("Successfully re-authenticated, but got error executing request: %s", e.ErrOriginal)
273 return e.choseErrString()
276 // ErrServiceNotFound is returned when no service in a service catalog matches
277 // the provided EndpointOpts. This is generally returned by provider service
278 // factory methods like "NewComputeV2()" and can mean that a service is not
279 // enabled for your account.
280 type ErrServiceNotFound struct {
284 func (e ErrServiceNotFound) Error() string {
285 e.DefaultErrString = "No suitable service could be found in the service catalog."
286 return e.choseErrString()
289 // ErrEndpointNotFound is returned when no available endpoints match the
290 // provided EndpointOpts. This is also generally returned by provider service
291 // factory methods, and usually indicates that a region was specified
293 type ErrEndpointNotFound struct {
297 func (e ErrEndpointNotFound) Error() string {
298 e.DefaultErrString = "No suitable endpoint could be found in the service catalog."
299 return e.choseErrString()
302 // ErrResourceNotFound is the error when trying to retrieve a resource's
303 // ID by name and the resource doesn't exist.
304 type ErrResourceNotFound struct {
310 func (e ErrResourceNotFound) Error() string {
311 e.DefaultErrString = fmt.Sprintf("Unable to find %s with name %s", e.ResourceType, e.Name)
312 return e.choseErrString()
315 // ErrMultipleResourcesFound is the error when trying to retrieve a resource's
316 // ID by name and multiple resources have the user-provided name.
317 type ErrMultipleResourcesFound struct {
324 func (e ErrMultipleResourcesFound) Error() string {
325 e.DefaultErrString = fmt.Sprintf("Found %d %ss matching %s", e.Count, e.ResourceType, e.Name)
326 return e.choseErrString()
329 // ErrUnexpectedType is the error when an unexpected type is encountered
330 type ErrUnexpectedType struct {
336 func (e ErrUnexpectedType) Error() string {
337 e.DefaultErrString = fmt.Sprintf("Expected %s but got %s", e.Expected, e.Actual)
338 return e.choseErrString()
341 func unacceptedAttributeErr(attribute string) string {
342 return fmt.Sprintf("The base Identity V3 API does not accept authentication by %s", attribute)
345 func redundantWithTokenErr(attribute string) string {
346 return fmt.Sprintf("%s may not be provided when authenticating with a TokenID", attribute)
349 func redundantWithUserID(attribute string) string {
350 return fmt.Sprintf("%s may not be provided when authenticating with a UserID", attribute)
353 // ErrAPIKeyProvided indicates that an APIKey was provided but can't be used.
354 type ErrAPIKeyProvided struct{ BaseError }
356 func (e ErrAPIKeyProvided) Error() string {
357 return unacceptedAttributeErr("APIKey")
360 // ErrTenantIDProvided indicates that a TenantID was provided but can't be used.
361 type ErrTenantIDProvided struct{ BaseError }
363 func (e ErrTenantIDProvided) Error() string {
364 return unacceptedAttributeErr("TenantID")
367 // ErrTenantNameProvided indicates that a TenantName was provided but can't be used.
368 type ErrTenantNameProvided struct{ BaseError }
370 func (e ErrTenantNameProvided) Error() string {
371 return unacceptedAttributeErr("TenantName")
374 // ErrUsernameWithToken indicates that a Username was provided, but token authentication is being used instead.
375 type ErrUsernameWithToken struct{ BaseError }
377 func (e ErrUsernameWithToken) Error() string {
378 return redundantWithTokenErr("Username")
381 // ErrUserIDWithToken indicates that a UserID was provided, but token authentication is being used instead.
382 type ErrUserIDWithToken struct{ BaseError }
384 func (e ErrUserIDWithToken) Error() string {
385 return redundantWithTokenErr("UserID")
388 // ErrDomainIDWithToken indicates that a DomainID was provided, but token authentication is being used instead.
389 type ErrDomainIDWithToken struct{ BaseError }
391 func (e ErrDomainIDWithToken) Error() string {
392 return redundantWithTokenErr("DomainID")
395 // ErrDomainNameWithToken indicates that a DomainName was provided, but token authentication is being used instead.s
396 type ErrDomainNameWithToken struct{ BaseError }
398 func (e ErrDomainNameWithToken) Error() string {
399 return redundantWithTokenErr("DomainName")
402 // ErrUsernameOrUserID indicates that neither username nor userID are specified, or both are at once.
403 type ErrUsernameOrUserID struct{ BaseError }
405 func (e ErrUsernameOrUserID) Error() string {
406 return "Exactly one of Username and UserID must be provided for password authentication"
409 // ErrDomainIDWithUserID indicates that a DomainID was provided, but unnecessary because a UserID is being used.
410 type ErrDomainIDWithUserID struct{ BaseError }
412 func (e ErrDomainIDWithUserID) Error() string {
413 return redundantWithUserID("DomainID")
416 // ErrDomainNameWithUserID indicates that a DomainName was provided, but unnecessary because a UserID is being used.
417 type ErrDomainNameWithUserID struct{ BaseError }
419 func (e ErrDomainNameWithUserID) Error() string {
420 return redundantWithUserID("DomainName")
423 // ErrDomainIDOrDomainName indicates that a username was provided, but no domain to scope it.
424 // It may also indicate that both a DomainID and a DomainName were provided at once.
425 type ErrDomainIDOrDomainName struct{ BaseError }
427 func (e ErrDomainIDOrDomainName) Error() string {
428 return "You must provide exactly one of DomainID or DomainName to authenticate by Username"
431 // ErrMissingPassword indicates that no password was provided and no token is available.
432 type ErrMissingPassword struct{ BaseError }
434 func (e ErrMissingPassword) Error() string {
435 return "You must provide a password to authenticate"
438 // ErrScopeDomainIDOrDomainName indicates that a domain ID or Name was required in a Scope, but not present.
439 type ErrScopeDomainIDOrDomainName struct{ BaseError }
441 func (e ErrScopeDomainIDOrDomainName) Error() string {
442 return "You must provide exactly one of DomainID or DomainName in a Scope with ProjectName"
445 // ErrScopeProjectIDOrProjectName indicates that both a ProjectID and a ProjectName were provided in a Scope.
446 type ErrScopeProjectIDOrProjectName struct{ BaseError }
448 func (e ErrScopeProjectIDOrProjectName) Error() string {
449 return "You must provide at most one of ProjectID or ProjectName in a Scope"
452 // ErrScopeProjectIDAlone indicates that a ProjectID was provided with other constraints in a Scope.
453 type ErrScopeProjectIDAlone struct{ BaseError }
455 func (e ErrScopeProjectIDAlone) Error() string {
456 return "ProjectID must be supplied alone in a Scope"
459 // ErrScopeEmpty indicates that no credentials were provided in a Scope.
460 type ErrScopeEmpty struct{ BaseError }
462 func (e ErrScopeEmpty) Error() string {
463 return "You must provide either a Project or Domain in a Scope"
466 // ErrAppCredMissingSecret indicates that no Application Credential Secret was provided with Application Credential ID or Name
467 type ErrAppCredMissingSecret struct{ BaseError }
469 func (e ErrAppCredMissingSecret) Error() string {
470 return "You must provide an Application Credential Secret"