{"record":{"id":"eabd71ac5dedc68d","repo":"go-kratos/kratos","slug":"parsing-list-q-w","errorCode":null,"errorMessage":"parsing list %q: %w","messagePattern":"parsing list %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"encoding/form/proto_decode.go","lineNumber":133,"sourceCode":"}\n\nfunc populateField(fd protoreflect.FieldDescriptor, v protoreflect.Message, value string) error {\n\tif value == \"\" {\n\t\treturn nil\n\t}\n\tval, err := parseField(fd, value)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parsing field %q: %w\", fd.FullName().Name(), err)\n\t}\n\tv.Set(fd, val)\n\treturn nil\n}\n\nfunc populateRepeatedField(fd protoreflect.FieldDescriptor, list protoreflect.List, values []string) error {\n\tfor _, value := range values {\n\t\tv, err := parseField(fd, value)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"parsing list %q: %w\", fd.FullName().Name(), err)\n\t\t}\n\t\tlist.Append(v)\n\t}\n\treturn nil\n}\n\nfunc populateMapField(fd protoreflect.FieldDescriptor, mp protoreflect.Map, fieldPath []string, values []string) error {\n\t_, keyName, err := parseURLQueryMapKey(strings.Join(fieldPath, fieldSeparator))\n\tif err != nil {\n\t\treturn err\n\t}\n\tkey, err := parseField(fd.MapKey(), keyName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parsing map key %q: %w\", fd.FullName().Name(), err)\n\t}\n\tvalue, err := parseField(fd.MapValue(), values[len(values)-1])\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parsing map value %q: %w\", fd.FullName().Name(), err)","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/encoding/form/proto_decode.go#L115-L151","documentation":"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.","triggerScenarios":"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.","commonSituations":"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'.","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"],"exampleFix":"// proto: repeated int64 ids = 1;\n// before: GET /batch?ids=1&ids=abc -> parsing list \"ids\": strconv.ParseInt: parsing \"abc\": invalid syntax\n// after:  GET /batch?ids=1&ids=2","handlingStrategy":"validation","validationCode":"// Validate every element of repeated params before sending\nfunc validateList(q url.Values, key string, parse func(string) error) error {\n\tfor _, v := range q[key] {\n\t\tif err := parse(v); err != nil {\n\t\t\treturn fmt.Errorf(\"%s[]=%q: %w\", key, v, err)\n\t\t}\n\t}\n\treturn nil\n}\n// usage: validateList(q, \"ids\", func(s string) error { _, e := strconv.ParseInt(s,10,64); return e })","typeGuard":null,"tryCatchPattern":"if err := binding.BindQuery(msg, q); err != nil {\n\tif strings.Contains(err.Error(), \"parsing list\") {\n\t\treturn errors.BadRequest(\"BAD_LIST_ELEMENT\", err.Error()) // includes field + strconv cause\n\t}\n}","preventionTips":["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"],"tags":["go","kratos","form-binding","protobuf","repeated","validation"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}