redis/go-redis · error
unexpected type %T, want map or key/value array
Error message
unexpected type %T, want map or key/value array
What it means
parseCollectEntry accepts only a map[string]interface{} (RESP3) or a flat even-length []interface{} (RESP2) as a COLLECT entry. Any other type (string, int64, nil inside the array, nested arrays) is rejected with this error naming the actual type found.
Source
Thrown at search_collect.go:233
}
return out, nil
case map[string]interface{}: // already string-keyed
return m, nil
case []interface{}: // RESP2 flat [field, value, field, value, ...]
if len(m)%2 != 0 {
return nil, fmt.Errorf("odd-length key/value array of length %d", len(m))
}
out := make(CollectEntry, len(m)/2)
for i := 0; i < len(m); i += 2 {
key, ok := m[i].(string)
if !ok {
key = fmt.Sprint(m[i])
}
out[key] = m[i+1]
}
return out, nil
default:
return nil, fmt.Errorf("unexpected type %T, want map or key/value array", e)
}
}
View on GitHub (pinned to c5cad058c7)
Solutions
- Inspect the %T in the message and correct the reply source (server version, proxy) to emit maps or flat arrays
- Use RESP3 so entries decode as map[string]interface{}
- Fix test fixtures to use realistic map or flat-array entries
Example fix
// before
arr := []interface{}{"just-a-string"} // entry is not a map or kv array
// after
arr := []interface{}{map[string]interface{}{"name": "v"}} Defensive patterns
Strategy: type-guard
Type guard
func isCollectEntry(v interface{}) bool {
switch v.(type) {
case map[string]interface{}:
return true
case []interface{}:
arr := v.([]interface{})
return len(arr)%2 == 0
default:
return false
}
} Prevention
- Read the %T in the error message to identify the unexpected shape
- Use RESP3 so entries decode as map[string]interface{}
- Fix test fixtures to use realistic map or flat-array entries
When it happens
Trigger: A COLLECT reply array containing an element of an unexpected Go type (e.g. a scalar or nested array) passed to parseCollectEntry from parseCollectValue.
Common situations: Proxies or non-standard module versions emitting entries in an unlisted shape; test fixtures with hand-built reply values of the wrong type.
Related errors
- redis: COLLECT value has type %T, want array of entries
- redis: COLLECT entry %d: %w
- odd-length key/value array of length %d
- redis: can't parse int reply: %.100q
- redis: FT.AGGREGATE COLLECT: empty field name in Fields
AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01).
Data as JSON: /api/errors/5fb82a6628f052ba.
Report an issue: GitHub.