fielderrors

package
v0.0.0-...-bf2aed5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2015 License: Apache-2.0 Imports: 4 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewValidationErrorFieldPrefixMatcher

func NewValidationErrorFieldPrefixMatcher(prefix string) errors.Matcher

NewValidationErrorFieldPrefixMatcher returns an errors.Matcher that returns true if the provided error is a ValidationError and has a field with the provided prefix.

func NewValidationErrorTypeMatcher

func NewValidationErrorTypeMatcher(t ValidationErrorType) errors.Matcher

NewValidationErrorFieldPrefixMatcher returns an errors.Matcher that returns true if the provided error is a ValidationError and has the provided ValidationErrorType.

Types

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 NewFieldRequired

func NewFieldRequired(field string) *ValidationError

NewFieldRequired returns a *ValidationError indicating "value required"

func NewFieldTooLong

func NewFieldTooLong(field string, value interface{}, maxLength int) *ValidationError

func NewFieldValueNotSupported

func NewFieldValueNotSupported(field string, value interface{}, validValues []string) *ValidationError

NewFieldValueNotSupported returns a *ValidationError indicating "unsupported value"

func (*ValidationError) Error

func (v *ValidationError) Error() string

func (*ValidationError) ErrorBody

func (v *ValidationError) ErrorBody() string

type ValidationErrorList

type ValidationErrorList []error

func (ValidationErrorList) Filter

Filter removes items from the ValidationErrorList that match the provided fns.

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"
	// ValidationErrorTypeTooLong is used to report that given value is too long.
	ValidationErrorTypeTooLong ValidationErrorType = "FieldValueTooLong"
)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL