Skip to content

Commit bf461e7

Browse files
committed
Adding TooMany error type
1 parent 4fda120 commit bf461e7

File tree

1 file changed

+13
-0
lines changed
  • staging/src/k8s.io/apimachinery/pkg/util/validation/field

1 file changed

+13
-0
lines changed

staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ const (
116116
// This is similar to ErrorTypeInvalid, but the error will not include the
117117
// too-long value. See TooLong().
118118
ErrorTypeTooLong ErrorType = "FieldValueTooLong"
119+
// ErrorTypeTooMany is used to report "too many". This is used to
120+
// report that a given list has too many items. This is similar to FieldValueTooLong,
121+
// but the error indicates quantity instead of length.
122+
ErrorTypeTooMany ErrorType = "FieldValueTooMany"
119123
// ErrorTypeInternal is used to report other errors that are not related
120124
// to user input. See InternalError().
121125
ErrorTypeInternal ErrorType = "InternalError"
@@ -138,6 +142,8 @@ func (t ErrorType) String() string {
138142
return "Forbidden"
139143
case ErrorTypeTooLong:
140144
return "Too long"
145+
case ErrorTypeTooMany:
146+
return "Too many"
141147
case ErrorTypeInternal:
142148
return "Internal error"
143149
default:
@@ -201,6 +207,13 @@ func TooLong(field *Path, value interface{}, maxLength int) *Error {
201207
return &Error{ErrorTypeTooLong, field.String(), value, fmt.Sprintf("must have at most %d characters", maxLength)}
202208
}
203209

210+
// TooMany returns a *Error indicating "too many". This is used to
211+
// report that a given list has too many items. This is similar to TooLong,
212+
// but the returned error indicates quantity instead of length.
213+
func TooMany(field *Path, actualQuantity, maxQuantity int) *Error {
214+
return &Error{ErrorTypeTooMany, field.String(), actualQuantity, fmt.Sprintf("must have at most %d items", maxQuantity)}
215+
}
216+
204217
// InternalError returns a *Error indicating "internal error". This is used
205218
// to signal that an error was found that was not directly related to user
206219
// input. The err argument must be non-nil.

0 commit comments

Comments
 (0)