{"id":"483fbfc22780f6b8","repo":"go-redis/redis","slug":"invalid-field-key-format","errorCode":null,"errorMessage":"invalid field key format","messagePattern":"invalid field key format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":936,"sourceCode":"\t}\n\n\ttotal, ok := data[0].(int64)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid total format\")\n\t}\n\n\trows := make([]AggregateRow, 0, len(data)-1)\n\tfor _, row := range data[1:] {\n\t\tfields, ok := row.([]interface{})\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"invalid row format\")\n\t\t}\n\n\t\trowMap := make(map[string]interface{})\n\t\tfor i := 0; i < len(fields); i += 2 {\n\t\t\tkey, ok := fields[i].(string)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid field key format\")\n\t\t\t}\n\t\t\tvalue := fields[i+1]\n\t\t\trowMap[key] = value\n\t\t}\n\t\trows = append(rows, AggregateRow{Fields: rowMap})\n\t}\n\n\tresult := &FTAggregateResult{\n\t\tTotal: int(total),\n\t\tRows:  rows,\n\t}\n\treturn result, nil\n}\n\nfunc NewAggregateCmd(ctx context.Context, args ...interface{}) *AggregateCmd {\n\treturn &AggregateCmd{\n\t\tbaseCmd: baseCmd{\n\t\t\tctx:     ctx,","sourceCodeStart":918,"sourceCodeEnd":954,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/search_commands.go#L918-L954","documentation":"Returned by ProcessAggregateResult when iterating a RESP2 row's flat [key, value, ...] array and a key-position element is not a string. Field names in FT.AGGREGATE rows must be bulk strings; a non-string key (number, nil, nested type) indicates a malformed or shifted row.","triggerScenarios":"AggregateCmd.readReply decoding a RESP2 row where fields[i] (i even) is not a string. Triggered during row decoding inside ProcessAggregateResult.","commonSituations":"An odd-length row shifted key/value alignment (the loop assumes even=keys). Server/proxy bug emitting a non-string key. RESP3/RESP2 mismatch. A NULL placeholder where a field key was expected.","solutions":["Inspect cmd.RawVal() to see the exact row contents and locate the non-string key.","Confirm the row array has an even length (an odd length implies truncation upstream).","Verify protocol negotiation and server version against the expected FT.AGGREGATE reply shape.","Reproduce with redis-cli; if the server emits the non-string key, report it upstream."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"res, err := cmd.Result()\nif err != nil && strings.Contains(err.Error(), \"invalid field key format\") {\n    raw, _ := cmd.RawResult()\n    log.Printf(\"aggregate field key not string; raw=%v\", raw)\n}\nreturn err","preventionTips":["Confirm rows have even-length field arrays (odd lengths imply upstream truncation).","Match client protocol to server reply type.","Reproduce with redis-cli to localize non-string keys."],"tags":["ft-aggregate","response-decoding","resp2","type-mismatch"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}