{"id":"a9b21d4dfeac0233","repo":"go-redis/redis","slug":"invalid-total-format","errorCode":null,"errorMessage":"invalid total format","messagePattern":"invalid total format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":922,"sourceCode":"\t\t}\n\n\t\tif options.DialectVersion > 0 {\n\t\t\tqueryArgs = append(queryArgs, \"DIALECT\", options.DialectVersion)\n\t\t} else {\n\t\t\tqueryArgs = append(queryArgs, \"DIALECT\", 2)\n\t\t}\n\t}\n\treturn queryArgs, nil\n}\n\nfunc ProcessAggregateResult(data []interface{}) (*FTAggregateResult, error) {\n\tif len(data) == 0 {\n\t\treturn nil, fmt.Errorf(\"no data returned\")\n\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}","sourceCodeStart":904,"sourceCodeEnd":940,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/search_commands.go#L904-L940","documentation":"Returned by ProcessAggregateResult when the first element of the RESP2 reply (the total-results count) is not an int64. The expected layout is [int64 total, row, row, ...]; anything else (string, nil, nested array) means the frame does not match the FT.AGGREGATE RESP2 contract.","triggerScenarios":"AggregateCmd.readReply decoding a RESP2 reply where data[0] cannot be asserted to int64. Triggered during response decoding.","commonSituations":"Server returned an error string as the first element instead of a proper reply. RESP3/RESP2 protocol mismatch. A reply from a different command being parsed as FT.AGGREGATE. Proxy rewriting the frame. Server version that changed the reply shape.","solutions":["Inspect cmd.RawVal() to see the actual type of data[0].","Confirm the command actually sent was FT.AGGREGATE and the reply is being decoded by AggregateCmd (not misrouted).","Verify the negotiated protocol matches the server reply type.","Reproduce with redis-cli to determine whether the malformed total originates at the server."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func replyHasInt64Total(data []interface{}) bool {\n\treturn len(data) > 0\n}\n// strong guard after decoding:\n// _, ok := data[0].(int64)","tryCatchPattern":"res, err := cmd.Result()\nif err != nil && strings.Contains(err.Error(), \"invalid total format\") {\n    raw, _ := cmd.RawResult()\n    log.Printf(\"aggregate total not int64; raw=%v\", raw)\n}\nreturn err","preventionTips":["Confirm the command sent was FT.AGGREGATE and that AggregateCmd is decoding it.","Match client protocol to the server reply type.","Reproduce with redis-cli to see whether the malformed total originates at the server."],"tags":["ft-aggregate","response-decoding","resp2","type-mismatch"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}