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

  1. Inspect the wrapped strconv error and validate each element client-side against the element type before serializing the repeated param
  2. Trim whitespace and drop empty elements when building lists ('ids=1&ids=2', not trailing empty entries)
  3. If the list legitimately contains heterogeneous strings, change the proto element type to string
  4. 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

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


AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16). Data as JSON: /api/errors/eabd71ac5dedc68d. Report an issue: GitHub.