{"record":{"id":"5fb82a6628f052ba","repo":"redis/go-redis","slug":"unexpected-type-t-want-map-or-key-value-array","errorCode":null,"errorMessage":"unexpected type %T, want map or key/value array","messagePattern":"unexpected type %T, want map or key/value array","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_collect.go","lineNumber":233,"sourceCode":"\t\t}\n\t\treturn out, nil\n\tcase map[string]interface{}: // already string-keyed\n\t\treturn m, nil\n\tcase []interface{}: // RESP2 flat [field, value, field, value, ...]\n\t\tif len(m)%2 != 0 {\n\t\t\treturn nil, fmt.Errorf(\"odd-length key/value array of length %d\", len(m))\n\t\t}\n\t\tout := make(CollectEntry, len(m)/2)\n\t\tfor i := 0; i < len(m); i += 2 {\n\t\t\tkey, ok := m[i].(string)\n\t\t\tif !ok {\n\t\t\t\tkey = fmt.Sprint(m[i])\n\t\t\t}\n\t\t\tout[key] = m[i+1]\n\t\t}\n\t\treturn out, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unexpected type %T, want map or key/value array\", e)\n\t}\n}\n","sourceCodeStart":215,"sourceCodeEnd":236,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/search_collect.go#L215-L236","documentation":"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.","triggerScenarios":"A COLLECT reply array containing an element of an unexpected Go type (e.g. a scalar or nested array) passed to parseCollectEntry from parseCollectValue.","commonSituations":"Proxies or non-standard module versions emitting entries in an unlisted shape; test fixtures with hand-built reply values of the wrong type.","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"],"exampleFix":"// before\narr := []interface{}{\"just-a-string\"} // entry is not a map or kv array\n// after\narr := []interface{}{map[string]interface{}{\"name\": \"v\"}}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isCollectEntry(v interface{}) bool {\n    switch v.(type) {\n    case map[string]interface{}:\n        return true\n    case []interface{}:\n        arr := v.([]interface{})\n        return len(arr)%2 == 0\n    default:\n        return false\n    }\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["search","collect","reply-parsing","type-mismatch"],"backgroundTag":"unexpected-reply-shape","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}