Skip to content

FT.SEARCH: Cannot read properties of undefined (reading 'length') #2772

Open
@nxps

Description

@nxps

Description

Usage: client.ft.search(index, query, option)
Exception: Cannot read properties of undefined (reading 'length')
Error location: https://github.com/redis/node-redis/blob/master/packages/search/lib/commands/SEARCH.ts
while (i < tuples.length) {

The debug log shows that the reply value is [100, [] ]

export type SearchRawReply = Array<any>;

export function transformReply(reply: SearchRawReply, withoutDocuments: boolean): SearchReply {
    const documents = [];
    let i = 1;
    while (i < reply.length) {
        documents.push({
            id: reply[i++],
            value: withoutDocuments ? Object.create(null) : documentValue(reply[i++])
        });
    }

    return {
        total: reply[0],
        documents
    };
}

function documentValue(tuples: any) {
    const message = Object.create(null);

    let i = 0;
    while (i < tuples.length) {
        const key = tuples[i++],
            value = tuples[i++];
        if (key === '$') { // might be a JSON reply
            try {
                Object.assign(message, JSON.parse(value));
                continue;
            } catch {
                // set as a regular property if not a valid JSON
            }
        }

        message[key] = value;
    }

    return message;
}

Node.js Version

v18.19.1

Redis Server Version

6.2.6

Node Redis Version

4.6.14

Platform

macOS

Logs

"TypeError: Cannot read properties of undefined (reading 'length')
    at documentValue (/Users/my/test/node_modules/@redis/search/dist/commands/SEARCH.js:30:23)
    at Object.transformReply (/Users/my/test/node_modules/@redis/search/dist/commands/SEARCH.js:18:61)
    at transformCommandReply (/Users/my/test/node_modules/@redis/client/dist/lib/commander.js:90:20)
    at Commander.commandsExecutor (/Users/my/test/node_modules/@redis/client/dist/lib/client/index.js:190:54)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions