@@ -116,6 +116,10 @@ const (
116
116
// This is similar to ErrorTypeInvalid, but the error will not include the
117
117
// too-long value. See TooLong().
118
118
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"
119
123
// ErrorTypeInternal is used to report other errors that are not related
120
124
// to user input. See InternalError().
121
125
ErrorTypeInternal ErrorType = "InternalError"
@@ -138,6 +142,8 @@ func (t ErrorType) String() string {
138
142
return "Forbidden"
139
143
case ErrorTypeTooLong :
140
144
return "Too long"
145
+ case ErrorTypeTooMany :
146
+ return "Too many"
141
147
case ErrorTypeInternal :
142
148
return "Internal error"
143
149
default :
@@ -201,6 +207,13 @@ func TooLong(field *Path, value interface{}, maxLength int) *Error {
201
207
return & Error {ErrorTypeTooLong , field .String (), value , fmt .Sprintf ("must have at most %d characters" , maxLength )}
202
208
}
203
209
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
+
204
217
// InternalError returns a *Error indicating "internal error". This is used
205
218
// to signal that an error was found that was not directly related to user
206
219
// input. The err argument must be non-nil.
0 commit comments