Documentation ¶
Overview ¶
Package errors provides detailed error types for api field validation.
Index ¶
- Constants
- func FromObject(obj runtime.Object) error
- func IsAlreadyExists(err error) bool
- func IsBadRequest(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsInvalid(err error) bool
- func IsMethodNotSupported(err error) bool
- func IsNotFound(err error) bool
- func IsServerTimeout(err error) bool
- func NewAlreadyExists(kind, name string) error
- func NewBadRequest(reason string) error
- func NewConflict(kind, name string, err error) error
- func NewForbidden(kind, name string, err error) error
- func NewInternalError(err error) error
- func NewInvalid(kind, name string, errs ValidationErrorList) error
- func NewMethodNotSupported(kind, action string) error
- func NewNotFound(kind, name string) error
- func NewServerTimeout(kind, operation string) error
- func NewTimeoutError(message string) error
- type StatusError
- type UnexpectedObjectError
- type ValidationError
- func NewFieldDuplicate(field string, value interface{}) *ValidationError
- func NewFieldForbidden(field string, value interface{}) *ValidationError
- func NewFieldInvalid(field string, value interface{}, detail string) *ValidationError
- func NewFieldNotFound(field string, value interface{}) *ValidationError
- func NewFieldNotSupported(field string, value interface{}) *ValidationError
- func NewFieldRequired(field string, value interface{}) *ValidationError
- type ValidationErrorList
- type ValidationErrorType
Constants ¶
const ( StatusUnprocessableEntity = 422 StatusTooManyRequests = 429 // HTTP recommendations are for servers to define 5xx error codes // for scenarios not covered by behavior. In this case, ServerTimeout // is an indication that a transient server error has occured and the // client *should* retry, with an optional Retry-After header to specify // the back off window. StatusServerTimeout = 504 )
HTTP Status codes not in the golang http package.
Variables ¶
This section is empty.
Functions ¶
func FromObject ¶
FromObject generates an StatusError from an api.Status, if that is the type of obj; otherwise, returns an UnexpecteObjectError.
func IsAlreadyExists ¶
IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists.
func IsBadRequest ¶
IsBadRequest determines if err is an error which indicates that the request is invalid.
func IsConflict ¶
IsConflict determines if the err is an error which indicates the provided update conflicts.
func IsForbidden ¶
IsForbidden determines if err is an error which indicates that the request is forbidden and cannot be completed as requested.
func IsInvalid ¶
IsInvalid determines if the err is an error which indicates the provided resource is not valid.
func IsMethodNotSupported ¶
IsMethodNotSupported determines if the err is an error which indicates the provided action could not be performed because it is not supported by the server.
func IsNotFound ¶
IsNotFound returns true if the specified error was created by NewNotFoundErr.
func IsServerTimeout ¶
IsServerTimeout determines if err is an error which indicates that the request needs to be retried by the client.
func NewAlreadyExists ¶
NewAlreadyExists returns an error indicating the item requested exists by that identifier.
func NewBadRequest ¶
NewBadRequest creates an error that indicates that the request is invalid and can not be processed.
func NewConflict ¶
NewConflict returns an error indicating the item can't be updated as provided.
func NewForbidden ¶
NewForbidden returns an error indicating the requested action was forbidden
func NewInternalError ¶
NewInternalError returns an error indicating the item is invalid and cannot be processed.
func NewInvalid ¶
func NewInvalid(kind, name string, errs ValidationErrorList) error
NewInvalid returns an error indicating the item is invalid and cannot be processed.
func NewMethodNotSupported ¶
NewMethodNotSupported returns an error indicating the requested action is not supported on this kind.
func NewNotFound ¶
NewNotFound returns a new error which indicates that the resource of the kind and the name was not found.
func NewServerTimeout ¶
NewServerTimeout returns an error indicating the requested action could not be completed due to a transient error, and the client should try again.
func NewTimeoutError ¶
NewTimeoutError returns an error indicating that a timeout occurred before the request could be completed. Clients may retry, but the operation may still complete.
Types ¶
type StatusError ¶
StatusError is an error intended for consumption by a REST API server; it can also be reconstructed by clients from a REST response. Public to allow easy type switches.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
Error implements the Error interface.
func (*StatusError) Status ¶
func (e *StatusError) Status() api.Status
Status allows access to e's status without having to know the detailed workings of StatusError. Used by pkg/apiserver.
type UnexpectedObjectError ¶
UnexpectedObjectError can be returned by FromObject if it's passed a non-status object.
func (*UnexpectedObjectError) Error ¶
func (u *UnexpectedObjectError) Error() string
Error returns an error message describing 'u'.
type ValidationError ¶
type ValidationError struct { Type ValidationErrorType Field string BadValue interface{} Detail string }
ValidationError is an implementation of the 'error' interface, which represents an error of validation.
func NewFieldDuplicate ¶
func NewFieldDuplicate(field string, value interface{}) *ValidationError
NewFieldDuplicate returns a *ValidationError indicating "duplicate value"
func NewFieldForbidden ¶
func NewFieldForbidden(field string, value interface{}) *ValidationError
NewFieldForbidden returns a *ValidationError indicating "forbidden"
func NewFieldInvalid ¶
func NewFieldInvalid(field string, value interface{}, detail string) *ValidationError
NewFieldInvalid returns a *ValidationError indicating "invalid value"
func NewFieldNotFound ¶
func NewFieldNotFound(field string, value interface{}) *ValidationError
NewFieldNotFound returns a *ValidationError indicating "value not found"
func NewFieldNotSupported ¶
func NewFieldNotSupported(field string, value interface{}) *ValidationError
NewFieldNotSupported returns a *ValidationError indicating "unsupported value"
func NewFieldRequired ¶
func NewFieldRequired(field string, value interface{}) *ValidationError
NewFieldRequired returns a *ValidationError indicating "value required" TODO: remove "value"
func (*ValidationError) Error ¶
func (v *ValidationError) Error() string
type ValidationErrorList ¶
type ValidationErrorList []error
func (ValidationErrorList) Prefix ¶
func (list ValidationErrorList) Prefix(prefix string) ValidationErrorList
Prefix adds a prefix to the Field of every ValidationError in the list. Returns the list for convenience.
func (ValidationErrorList) PrefixIndex ¶
func (list ValidationErrorList) PrefixIndex(index int) ValidationErrorList
PrefixIndex adds an index to the Field of every ValidationError in the list. Returns the list for convenience.
type ValidationErrorType ¶
type ValidationErrorType string
ValidationErrorType is a machine readable value providing more detail about why a field is invalid. These values are expected to match 1-1 with CauseType in api/types.go.
const ( // ValidationErrorTypeNotFound is used to report failure to find a requested value // (e.g. looking up an ID). ValidationErrorTypeNotFound ValidationErrorType = "FieldValueNotFound" // ValidationErrorTypeRequired is used to report required values that are not // provided (e.g. empty strings, null values, or empty arrays). ValidationErrorTypeRequired ValidationErrorType = "FieldValueRequired" // ValidationErrorTypeDuplicate is used to report collisions of values that must be // unique (e.g. unique IDs). ValidationErrorTypeDuplicate ValidationErrorType = "FieldValueDuplicate" // ValidationErrorTypeInvalid is used to report malformed values (e.g. failed regex // match). ValidationErrorTypeInvalid ValidationErrorType = "FieldValueInvalid" // ValidationErrorTypeNotSupported is used to report valid (as per formatting rules) // values that can not be handled (e.g. an enumerated string). ValidationErrorTypeNotSupported ValidationErrorType = "FieldValueNotSupported" // ValidationErrorTypeForbidden is used to report valid (as per formatting rules) // values which would be accepted by some api instances, but which would invoke behavior // not permitted by this api instance (such as due to stricter security policy). ValidationErrorTypeForbidden ValidationErrorType = "FieldValueForbidden" )
TODO: These values are duplicated in api/types.go, but there's a circular dep. Fix it.
func (ValidationErrorType) String ¶
func (t ValidationErrorType) String() string
String converts a ValidationErrorType into its corresponding error message.