{"record":{"id":"6967f369a4866049","repo":"redis/go-redis","slug":"redis-collect-entry-d-w","errorCode":null,"errorMessage":"redis: COLLECT entry %d: %w","messagePattern":"redis: COLLECT entry (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_collect.go","lineNumber":198,"sourceCode":"\t}\n\treturn parseCollectValue(v)\n}\n\n// parseCollectValue decodes a raw COLLECT alias value (an array of entries)\n// into a CollectColumn.\nfunc parseCollectValue(v interface{}) (CollectColumn, error) {\n\tif v == nil {\n\t\treturn nil, nil\n\t}\n\tarr, ok := v.([]interface{})\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"redis: COLLECT value has type %T, want array of entries\", v)\n\t}\n\tout := make(CollectColumn, 0, len(arr))\n\tfor i, e := range arr {\n\t\tentry, err := parseCollectEntry(e)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"redis: COLLECT entry %d: %w\", i, err)\n\t\t}\n\t\tout = append(out, entry)\n\t}\n\treturn out, nil\n}\n\n// parseCollectEntry decodes a single collected entry from either the RESP3\n// map form or the RESP2 flat key/value array form into a CollectEntry. Keys\n// are passed through as-is: the server already returns them without the \"@\"\n// prefix.\nfunc parseCollectEntry(e interface{}) (CollectEntry, error) {\n\tswitch m := e.(type) {\n\tcase map[interface{}]interface{}: // RESP3\n\t\tout := make(CollectEntry, len(m))\n\t\tfor k, val := range m {\n\t\t\tout[fmt.Sprint(k)] = val\n\t\t}\n\t\treturn out, nil","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/search_collect.go#L180-L216","documentation":"Each entry inside the COLLECT array is parsed by parseCollectEntry; if any single entry fails (wrong shape, odd key/value array), parseCollectValue wraps that error with the entry's index via this %w-wrapped format. The underlying cause is preserved and accessible with errors.Is/As/Unwrap.","triggerScenarios":"A COLLECT reply array containing an entry that is neither a map[string]interface{} nor an even-length []interface{} flat key/value list; parseCollectEntry's error gets wrapped as \"redis: COLLECT entry %d: %w\".","commonSituations":"Mixed RESP2/RESP3 encodings from a proxy; server returning partial or malformed COLLECT entries; one malformed row among many valid ones.","solutions":["Inspect the wrapped cause with errors.Unwrap to identify the entry-shape problem","Fix the reply-shape root cause (server version / RESP protocol / proxy)","Skip or handle malformed entries defensively if replies may be heterogeneous"],"exampleFix":"// before\nif err != nil {\n    return err // loses which entry failed\n}\n// after\nif err != nil {\n    return fmt.Errorf(\"collect parse: %w\", err) // keeps \"COLLECT entry 3: ...\" context\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"col, err := cmd.Collect()\nif err != nil {\n    if strings.Contains(err.Error(), \"COLLECT entry\") {\n        log.Printf(\"malformed COLLECT entry: %v\", err)\n    }\n    return err\n}","preventionTips":["Wrap and log parse errors to keep the entry-index context","Test COLLECT parsing against the exact production server version","Avoid RESP-reshaping proxies"],"tags":["search","ft-aggregate","collect","reply-parsing","error-wrapping"],"backgroundTag":"unexpected-reply-shape","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}