go-kratos/kratos · warning
parsing list %q: %w
Error message
parsing list %q: %w
What it means
Form-binding decoder error wrapping the same parseField() failure as the singular case, but while appending elements to a repeated (list) field: one of the submitted values for the list key cannot be converted to the element kind. The error names the list field and preserves the underlying strconv error via %w.
Source
Thrown at encoding/form/proto_decode.go:133
}
func populateField(fd protoreflect.FieldDescriptor, v protoreflect.Message, value string) error {
if value == "" {
return nil
}
val, err := parseField(fd, value)
if err != nil {
return fmt.Errorf("parsing field %q: %w", fd.FullName().Name(), err)
}
v.Set(fd, val)
return nil
}
func populateRepeatedField(fd protoreflect.FieldDescriptor, list protoreflect.List, values []string) error {
for _, value := range values {
v, err := parseField(fd, value)
if err != nil {
return fmt.Errorf("parsing list %q: %w", fd.FullName().Name(), err)
}
list.Append(v)
}
return nil
}
func populateMapField(fd protoreflect.FieldDescriptor, mp protoreflect.Map, fieldPath []string, values []string) error {
_, keyName, err := parseURLQueryMapKey(strings.Join(fieldPath, fieldSeparator))
if err != nil {
return err
}
key, err := parseField(fd.MapKey(), keyName)
if err != nil {
return fmt.Errorf("parsing map key %q: %w", fd.FullName().Name(), err)
}
value, err := parseField(fd.MapValue(), values[len(values)-1])
if err != nil {
return fmt.Errorf("parsing map value %q: %w", fd.FullName().Name(), err)View on GitHub (pinned to 668db92c2c)
Solutions
- Inspect the wrapped strconv error and validate each element client-side against the element type before serializing the repeated param
- Trim whitespace and drop empty elements when building lists ('ids=1&ids=2', not trailing empty entries)
- If the list legitimately contains heterogeneous strings, change the proto element type to string
- During integration, log which value failed - the error includes the joined values only for the too-many-values sibling; here reproduce with the exact list contents
Example fix
// proto: repeated int64 ids = 1; // before: GET /batch?ids=1&ids=abc -> parsing list "ids": strconv.ParseInt: parsing "abc": invalid syntax // after: GET /batch?ids=1&ids=2
Defensive patterns
Strategy: validation
Validate before calling
// Validate every element of repeated params before sending
func validateList(q url.Values, key string, parse func(string) error) error {
for _, v := range q[key] {
if err := parse(v); err != nil {
return fmt.Errorf("%s[]=%q: %w", key, v, err)
}
}
return nil
}
// usage: validateList(q, "ids", func(s string) error { _, e := strconv.ParseInt(s,10,64); return e }) Try / catch
if err := binding.BindQuery(msg, q); err != nil {
if strings.Contains(err.Error(), "parsing list") {
return errors.BadRequest("BAD_LIST_ELEMENT", err.Error()) // includes field + strconv cause
}
} Prevention
- Trim and drop empty elements when joining ID lists (no trailing commas producing '')
- Type-check each element client-side with the same strconv call the server will use
- Keep element types stable in proto; if heterogeneous input is needed, accept strings and parse in the handler
- Include the failing list contents in error logs during development
When it happens
Trigger: A repeated key where at least one element is malformed: `?tags=a&tags=!!` where tags is repeated bytes with bad base64; `?ids=1&ids=x` for repeated int64; `?delays=1s&delays=fast` for repeated Duration.
Common situations: Batch endpoints collecting IDs where one entry is empty or non-numeric (trailing comma join producing '1,2,'), mixed client data types serialized through String(), copy-pasted values with whitespace/units, arrays containing a null rendered as the string 'null'.
Related errors
- invalid path: %q is not a message
- field already set for oneof %q
- too many values for field %q: %s
- parsing field %q: %w
- parsing map key %q: %w
AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16).
Data as JSON: /api/errors/eabd71ac5dedc68d.
Report an issue: GitHub.