{"id":"26e04da1de68bb8c","repo":"go-redis/redis","slug":"invalid-document-id-format","errorCode":null,"errorMessage":"invalid document ID format","messagePattern":"invalid document ID format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":2620,"sourceCode":"\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}\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\")","sourceCodeStart":2602,"sourceCodeEnd":2638,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/search_commands.go#L2602-L2638","documentation":"Thrown in parseFTSearch (search_commands.go:2618-2620) when iterating the RESP2 FT.SEARCH result array and an element expected to be a document ID is not a Go string. Each document slot must begin with a string key; a non-string (int, nil, nested array) indicates the reply is malformed or misaligned with the requested flags.","triggerScenarios":"Mismatched WITHSCORES/WITHPAYLOADS/WITHSORTKEYS flags between what the caller passed and what the server returned, so the parser reads a value where it expected an ID; or a corrupted/truncated reply.","commonSituations":"Server-side schema change that altered the reply layout, a fork or alternate RediSearch build emitting a different array shape, or the connection interleaved replies under pipelining.","solutions":["Confirm the FTSearchOptions flags (NoContent, WithScores, WithPayloads, WithSortKeys) match what you intend.","Use RawResult() to dump the full array and find the offending element index i.","Run the same FT.SEARCH via redis-cli to see the canonical reply.","Reproduce on the latest Redis Stack version to rule out a fixed parser bug."],"exampleFix":"// before\nres, err := client.FTSearchWithArgs(ctx, idx, q, &redis.FTSearchOptions{WithScores: true}).Result()\n// after — verify flags line up with the query you intended\nopts := &redis.FTSearchOptions{WithScores: true, NoContent: true}\nres, err := client.FTSearchWithArgs(ctx, idx, q, opts).Result()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"res, err := client.FTSearchWithArgs(ctx, idx, q, opts).Result()\nif err != nil && strings.Contains(err.Error(), \"invalid document ID format\") {\n    raw, _ := client.FTSearchWithArgs(ctx, idx, q, opts).RawResult()\n    log.Printf(\"doc id slot misaligned; raw=%#v\", raw)\n    return err\n}","preventionTips":["Keep WITHSCORES/WITHPAYLOADS/WITHSORTKEYS/NOCONTENT flags consistent with the query intent.","Avoid pipelining FT.SEARCH alongside replies that could interleave on a buggy connection.","Use RawResult() to debug shape mismatches."],"tags":["redisearch","ft-search","resp2","response-parsing"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}