{"record":{"id":"c1ec012789961503","repo":"redis/go-redis","slug":"invalid-score-format","errorCode":null,"errorMessage":"invalid score format","messagePattern":"invalid score format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":2638,"sourceCode":"\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}\n\t\ti++\n\n\t\tif noContent {\n\t\t\tresults = append(results, doc)\n\t\t\tcontinue\n\t\t}\n\n\t\tif withScores && i < len(data) {\n\t\t\tif scoreStr, ok := data[i].(string); ok {\n\t\t\t\tscore, err := strconv.ParseFloat(scoreStr, 64)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn FTSearchResult{}, fmt.Errorf(\"invalid score format\")\n\t\t\t\t}\n\t\t\t\tdoc.Score = &score\n\t\t\t\ti++\n\t\t\t}\n\t\t}\n\n\t\tif withPayloads && i < len(data) {\n\t\t\tif payload, ok := data[i].(string); ok {\n\t\t\t\tdoc.Payload = &payload\n\t\t\t\ti++\n\t\t\t}\n\t\t}\n\n\t\tif withSortKeys && i < len(data) {\n\t\t\tif sortKey, ok := data[i].(string); ok {\n\t\t\t\tdoc.SortKey = &sortKey\n\t\t\t\ti++\n\t\t\t}","sourceCodeStart":2620,"sourceCodeEnd":2656,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/search_commands.go#L2620-L2656","documentation":"When WithScores is set, FT.SEARCH returns each document's score as a string right after the ID. The string must parse as a float64 via strconv.ParseFloat; if it doesn't (empty, garbage, or non-numeric text), parsing aborts with this error.","triggerScenarios":"FTSearch(ctx, idx, q, &redis.FTSearchOptions{WithScores: true}) where the score element is a string that isn't a valid float — e.g. \"NAN\" variants from a patched server, a proxy substituting the value, or a mock with a bad score.","commonSituations":"Fault-injection proxies corrupting score fields; hand-written test replies with non-numeric scores; module versions emitting unexpected score encodings.","solutions":["Inspect the raw reply to see the actual score string","Fix the proxy/mock producing the bad score","Confirm the server is genuine RediSearch of a supported version","Update go-redis in case your module version changed score encoding"],"exampleFix":"// before: mock with bad score\nmock := []interface{}{int64(1), \"doc:1\", \"high\", []interface{}{}}\n\n// after: score must parse as float\ncmd := rdb.FTSearch(ctx, \"idx\", \"q\", &redis.FTSearchOptions{WithScores: true})\nmock := []interface{}{int64(1), \"doc:1\", \"0.98\", []interface{}{}}","handlingStrategy":"try-catch","validationCode":"// Pre-check that scores parse in captured/mock replies\nfor _, s := range scoreStrings {\n\tif _, err := strconv.ParseFloat(s, 64); err != nil {\n\t\tt.Fatalf(\"mock score %q is not a float\", s)\n\t}\n}","typeGuard":"func isParseableFloat(s interface{}) bool {\n\tstr, ok := s.(string)\n\tif !ok {\n\t\treturn false\n\t}\n\t_, err := strconv.ParseFloat(str, 64)\n\treturn err == nil\n}","tryCatchPattern":"res, err := rdb.FTSearch(ctx, \"idx\", q, &redis.FTSearchOptions{WithScores: true}).Result()\nif err != nil {\n\tif strings.Contains(err.Error(), \"invalid score format\") {\n\t\tlog.Printf(\"bad score in reply: %v\", err)\n\t\treturn resultWithoutScores, nil\n\t}\n\treturn err\n}","preventionTips":["Validate all mock score strings parse as floats","Bypass fault-injecting proxies on score-sensitive paths","Pin supported RediSearch versions"],"tags":["go-redis","ftsearch","scores","resp-parsing"],"backgroundTag":"resp-reply-parse-failed","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}