Documentation ¶
Index ¶
- func NewErrorTypeMatcher(t ErrorType) utilerrors.Matcher
- type Error
- func Duplicate(field *Path, value interface{}) *Error
- func Forbidden(field *Path, detail string) *Error
- func InternalError(field *Path, err error) *Error
- func Invalid(field *Path, value interface{}, detail string) *Error
- func NotFound(field *Path, value interface{}) *Error
- func NotSupported[T ~string](field *Path, value interface{}, validValues []T) *Error
- func Required(field *Path, detail string) *Error
- func TooLong(field *Path, value interface{}, maxLength int) *Error
- func TooLongMaxLength(field *Path, value interface{}, maxLength int) *Error
- func TooMany(field *Path, actualQuantity, maxQuantity int) *Error
- func TypeInvalid(field *Path, value interface{}, detail string) *Error
- type ErrorList
- type ErrorType
- type OmitValueType
- type Path
- type PathOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewErrorTypeMatcher ¶
func NewErrorTypeMatcher(t ErrorType) utilerrors.Matcher
NewErrorTypeMatcher returns an errors.Matcher that returns true if the provided error is a Error and has the provided ErrorType.
Types ¶
type Error ¶
Error is an implementation of the 'error' interface, which represents a field-level validation error.
func Duplicate ¶
Duplicate returns a *Error indicating "duplicate value". This is used to report collisions of values that must be unique (e.g. names or IDs).
func Forbidden ¶
Forbidden returns a *Error indicating "forbidden". This is used to report valid (as per formatting rules) values which would be accepted under some conditions, but which are not permitted by current conditions (e.g. security policy).
func InternalError ¶
InternalError returns a *Error indicating "internal error". This is used to signal that an error was found that was not directly related to user input. The err argument must be non-nil.
func Invalid ¶
Invalid returns a *Error indicating "invalid value". This is used to report malformed values (e.g. failed regex match, too long, out of bounds).
func NotFound ¶
NotFound returns a *Error indicating "value not found". This is used to report failure to find a requested value (e.g. looking up an ID).
func NotSupported ¶
NotSupported returns a *Error indicating "unsupported value". This is used to report unknown values for enumerated fields (e.g. a list of valid values).
func Required ¶
Required returns a *Error indicating "value required". This is used to report required values that are not provided (e.g. empty strings, null values, or empty arrays).
func TooLong ¶
TooLong returns a *Error indicating "too long". This is used to report that the given value is too long. This is similar to Invalid, but the returned error will not include the too-long value.
func TooLongMaxLength ¶ added in v0.24.0
TooLongMaxLength returns a *Error indicating "too long". This is used to report that the given value is too long. This is similar to Invalid, but the returned error will not include the too-long value. If maxLength is negative, no max length will be included in the message.
func TooMany ¶ added in v0.16.4
TooMany returns a *Error indicating "too many". This is used to report that a given list has too many items. This is similar to TooLong, but the returned error indicates quantity instead of length.
func TypeInvalid ¶ added in v0.24.0
TypeInvalid returns a *Error indicating "type is invalid"
type ErrorList ¶
type ErrorList []*Error
ErrorList holds a set of Errors. It is plausible that we might one day have non-field errors in this same umbrella package, but for now we don't, so we can keep it simple and leave ErrorList here.
func (ErrorList) Filter ¶
func (list ErrorList) Filter(fns ...utilerrors.Matcher) ErrorList
Filter removes items from the ErrorList that match the provided fns.
func (ErrorList) ToAggregate ¶
func (list ErrorList) ToAggregate() utilerrors.Aggregate
ToAggregate converts the ErrorList into an errors.Aggregate.
type ErrorType ¶
type ErrorType string
ErrorType 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 ( // ErrorTypeNotFound is used to report failure to find a requested value // (e.g. looking up an ID). See NotFound(). ErrorTypeNotFound ErrorType = "FieldValueNotFound" // ErrorTypeRequired is used to report required values that are not // provided (e.g. empty strings, null values, or empty arrays). See // Required(). ErrorTypeRequired ErrorType = "FieldValueRequired" // ErrorTypeDuplicate is used to report collisions of values that must be // unique (e.g. unique IDs). See Duplicate(). ErrorTypeDuplicate ErrorType = "FieldValueDuplicate" // ErrorTypeInvalid is used to report malformed values (e.g. failed regex // match, too long, out of bounds). See Invalid(). ErrorTypeInvalid ErrorType = "FieldValueInvalid" // ErrorTypeNotSupported is used to report unknown values for enumerated // fields (e.g. a list of valid values). See NotSupported(). ErrorTypeNotSupported ErrorType = "FieldValueNotSupported" // ErrorTypeForbidden is used to report valid (as per formatting rules) // values which would be accepted under some conditions, but which are not // permitted by the current conditions (such as security policy). See // Forbidden(). ErrorTypeForbidden ErrorType = "FieldValueForbidden" // ErrorTypeTooLong is used to report that the given value is too long. // This is similar to ErrorTypeInvalid, but the error will not include the // too-long value. See TooLong(). ErrorTypeTooLong ErrorType = "FieldValueTooLong" // ErrorTypeTooMany is used to report "too many". This is used to // report that a given list has too many items. This is similar to FieldValueTooLong, // but the error indicates quantity instead of length. ErrorTypeTooMany ErrorType = "FieldValueTooMany" // ErrorTypeInternal is used to report other errors that are not related // to user input. See InternalError(). ErrorTypeInternal ErrorType = "InternalError" // ErrorTypeTypeInvalid is for the value did not match the schema type for that field ErrorTypeTypeInvalid ErrorType = "FieldValueTypeInvalid" )
TODO: These values are duplicated in api/types.go, but there's a circular dep. Fix it.
type OmitValueType ¶ added in v0.25.0
type OmitValueType struct{}
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path represents the path from some root to a particular field.
func ToPath ¶ added in v0.21.0
func ToPath(opts ...PathOption) *Path
ToPath produces *Path from a set of PathOption
func (*Path) Index ¶
Index indicates that the previous Path is to be subscripted by an int. This sets the same underlying value as Key.
type PathOption ¶ added in v0.21.0
type PathOption func(o *pathOptions)
PathOption modifies a pathOptions