{"id":"938d6106870b7ea3","repo":"go-redis/redis","slug":"unexpected-search-result-format","errorCode":null,"errorMessage":"unexpected search result format","messagePattern":"unexpected search result format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":2608,"sourceCode":"\t\tval = make([]SpellCheckResult, len(cmd.val))\n\t\tfor i, result := range cmd.val {\n\t\t\tval[i] = SpellCheckResult{\n\t\t\t\tTerm: result.Term,\n\t\t\t}\n\t\t\tif result.Suggestions != nil {\n\t\t\t\tval[i].Suggestions = slices.Clone(result.Suggestions)\n\t\t\t}\n\t\t}\n\t}\n\treturn &FTSpellCheckCmd{\n\t\tbaseCmd: cmd.cloneBaseCmd(),\n\t\tval:     val,\n\t}\n}\n\nfunc parseFTSearch(data []interface{}, noContent, withScores, withPayloads, withSortKeys bool) (FTSearchResult, error) {\n\tif len(data) < 1 {\n\t\treturn FTSearchResult{}, fmt.Errorf(\"unexpected search result format\")\n\t}\n\n\ttotal, ok := data[0].(int64)\n\tif !ok {\n\t\treturn FTSearchResult{}, fmt.Errorf(\"invalid total results format\")\n\t}\n\n\tvar results []Document\n\tfor i := 1; i < len(data); {\n\t\tdocID, ok := data[i].(string)\n\t\tif !ok {\n\t\t\treturn FTSearchResult{}, fmt.Errorf(\"invalid document ID format\")\n\t\t}\n\n\t\tdoc := Document{\n\t\t\tID:     docID,\n\t\t\tFields: make(map[string]string),\n\t\t}","sourceCodeStart":2590,"sourceCodeEnd":2626,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/search_commands.go#L2590-L2626","documentation":"Returned by parseFTSearch when the reply array has fewer than 1 element. The FT.SEARCH reply always begins with a total-count integer; an empty reply means the server returned an unexpected (empty) payload. Guard at search_commands.go:2607.","triggerScenarios":"Calling FTSearch and the parsed reply data slice is empty (len(data) < 1). Typically a protocol/truncation issue rather than a normal zero-results case (zero results still returns a 1-element array with total 0).","commonSituations":"A proxy truncating replies, a RESP3/RESP2 mismatch causing the reader to consume the frame incorrectly, or a server crash mid-reply. Distinct from a legitimate empty search which returns [0].","solutions":["Confirm the server is reachable and the index exists before searching.","Check for a RESP-rewriting proxy and ensure the client Protocol setting matches the server.","Inspect the raw connection/reply (enable go-redis logging) to see if the frame was truncated."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"// Ensure index exists and server reachable before searching:\nif _, err := client.FTInfo(ctx, idx).Result(); err != nil {\n    return fmt.Errorf(\"index %q unavailable: %w\", idx, err)\n}","typeGuard":null,"tryCatchPattern":"res, err := client.FTSearch(ctx, idx, q).Result()\nif err != nil && strings.Contains(err.Error(), \"unexpected search result format\") {\n    // re-issue FTInfo to confirm index/server health; enable go-redis logging\n}","preventionTips":["Confirm the index exists (FTInfo) before searching.","Keep the client Protocol setting consistent with the server.","Enable internal.Logger to catch truncated/corrupt frames."],"tags":["redisearch","ft-search","parsing","protocol"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}