redis/go-redis · error
redis: COLLECT entry %d: %w
Error message
redis: COLLECT entry %d: %w
What it means
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.
Source
Thrown at search_collect.go:198
}
return parseCollectValue(v)
}
// parseCollectValue decodes a raw COLLECT alias value (an array of entries)
// into a CollectColumn.
func parseCollectValue(v interface{}) (CollectColumn, error) {
if v == nil {
return nil, nil
}
arr, ok := v.([]interface{})
if !ok {
return nil, fmt.Errorf("redis: COLLECT value has type %T, want array of entries", v)
}
out := make(CollectColumn, 0, len(arr))
for i, e := range arr {
entry, err := parseCollectEntry(e)
if err != nil {
return nil, fmt.Errorf("redis: COLLECT entry %d: %w", i, err)
}
out = append(out, entry)
}
return out, nil
}
// parseCollectEntry decodes a single collected entry from either the RESP3
// map form or the RESP2 flat key/value array form into a CollectEntry. Keys
// are passed through as-is: the server already returns them without the "@"
// prefix.
func parseCollectEntry(e interface{}) (CollectEntry, error) {
switch m := e.(type) {
case map[interface{}]interface{}: // RESP3
out := make(CollectEntry, len(m))
for k, val := range m {
out[fmt.Sprint(k)] = val
}
return out, nilView on GitHub (pinned to c5cad058c7)
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
Example fix
// before
if err != nil {
return err // loses which entry failed
}
// after
if err != nil {
return fmt.Errorf("collect parse: %w", err) // keeps "COLLECT entry 3: ..." context
} Defensive patterns
Strategy: try-catch
Try / catch
col, err := cmd.Collect()
if err != nil {
if strings.Contains(err.Error(), "COLLECT entry") {
log.Printf("malformed COLLECT entry: %v", err)
}
return err
} Prevention
- Wrap and log parse errors to keep the entry-index context
- Test COLLECT parsing against the exact production server version
- Avoid RESP-reshaping proxies
When it happens
Trigger: 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".
Common situations: Mixed RESP2/RESP3 encodings from a proxy; server returning partial or malformed COLLECT entries; one malformed row among many valid ones.
Related errors
- redis: COLLECT value has type %T, want array of entries
- redis: FT.AGGREGATE COLLECT: empty field name in Fields
- redis: FT.AGGREGATE COLLECT requires FieldsAll or a non-empt
- redis: FT.AGGREGATE COLLECT: empty field name in SortBy
- redis: FT.AGGREGATE COLLECT: ASC and DESC are mutually exclu
AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01).
Data as JSON: /api/errors/6967f369a4866049.
Report an issue: GitHub.