mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #81815 from robscott/error-type-too-many
Adding TooMany error type
This commit is contained in:
commit
5cc31b7aa2
@ -116,6 +116,10 @@ const (
|
|||||||
// This is similar to ErrorTypeInvalid, but the error will not include the
|
// This is similar to ErrorTypeInvalid, but the error will not include the
|
||||||
// too-long value. See TooLong().
|
// too-long value. See TooLong().
|
||||||
ErrorTypeTooLong ErrorType = "FieldValueTooLong"
|
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
|
// ErrorTypeInternal is used to report other errors that are not related
|
||||||
// to user input. See InternalError().
|
// to user input. See InternalError().
|
||||||
ErrorTypeInternal ErrorType = "InternalError"
|
ErrorTypeInternal ErrorType = "InternalError"
|
||||||
@ -138,6 +142,8 @@ func (t ErrorType) String() string {
|
|||||||
return "Forbidden"
|
return "Forbidden"
|
||||||
case ErrorTypeTooLong:
|
case ErrorTypeTooLong:
|
||||||
return "Too long"
|
return "Too long"
|
||||||
|
case ErrorTypeTooMany:
|
||||||
|
return "Too many"
|
||||||
case ErrorTypeInternal:
|
case ErrorTypeInternal:
|
||||||
return "Internal error"
|
return "Internal error"
|
||||||
default:
|
default:
|
||||||
@ -201,6 +207,13 @@ func TooLong(field *Path, value interface{}, maxLength int) *Error {
|
|||||||
return &Error{ErrorTypeTooLong, field.String(), value, fmt.Sprintf("must have at most %d characters", maxLength)}
|
return &Error{ErrorTypeTooLong, field.String(), value, fmt.Sprintf("must have at most %d characters", maxLength)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 TooMany(field *Path, actualQuantity, maxQuantity int) *Error {
|
||||||
|
return &Error{ErrorTypeTooMany, field.String(), actualQuantity, fmt.Sprintf("must have at most %d items", maxQuantity)}
|
||||||
|
}
|
||||||
|
|
||||||
// InternalError returns a *Error indicating "internal error". This is used
|
// InternalError returns a *Error indicating "internal error". This is used
|
||||||
// to signal that an error was found that was not directly related to user
|
// to signal that an error was found that was not directly related to user
|
||||||
// input. The err argument must be non-nil.
|
// input. The err argument must be non-nil.
|
||||||
|
Loading…
Reference in New Issue
Block a user