errors

package
v0.0.0-...-e20f597 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2014 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValueOf

func ValueOf(t ValidationErrorType) string

Types

type ErrorList

type ErrorList []error

ErrorList is a collection of errors. This does not implement the error interface to avoid confusion where an empty ErrorList would still be an error (non-nil). To produce a single error instance from an ErrorList, use the ToError() method, which will return nil for an empty ErrorList.

func (ErrorList) Prefix

func (list ErrorList) Prefix(prefix string) ErrorList

Prefix adds a prefix to the Field of every ValidationError in the list. Returns the list for convenience.

func (ErrorList) PrefixIndex

func (list ErrorList) PrefixIndex(index int) ErrorList

PrefixIndex adds an index to the Field of every ValidationError in the list. Returns the list for convenience.

func (ErrorList) ToError

func (list ErrorList) ToError() error

ToError converts an ErrorList into a "normal" error, or nil if the list is empty.

type ValidationError

type ValidationError struct {
	Type     ValidationErrorType
	Field    string
	BadValue interface{}
}

ValidationError is an implementation of the 'error' interface, which represents an error of validation.

func NewDuplicate

func NewDuplicate(field string, value interface{}) ValidationError

NewDuplicate returns a ValidationError indicating "duplicate value"

func NewInvalid

func NewInvalid(field string, value interface{}) ValidationError

NewInvalid returns a ValidationError indicating "invalid value"

func NewNotFound

func NewNotFound(field string, value interface{}) ValidationError

NewNotFound returns a ValidationError indicating "value not found"

func NewNotSupported

func NewNotSupported(field string, value interface{}) ValidationError

NewNotSupported returns a ValidationError indicating "unsupported value"

func NewRequired

func NewRequired(field string, value interface{}) ValidationError

NewInvalid returns a ValidationError indicating "value required"

func (ValidationError) Error

func (v ValidationError) Error() string

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"
)

Jump to

Keyboard shortcuts

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