Skip to content

Fix: TypeError - queries.map is not a function#1017

Open
bookkeepingofficeservices-cmyk wants to merge 3 commits intoItzCrazyKns:masterfrom
bookkeepingofficeservices-cmyk:fix-queries-map-error
Open

Fix: TypeError - queries.map is not a function#1017
bookkeepingofficeservices-cmyk wants to merge 3 commits intoItzCrazyKns:masterfrom
bookkeepingofficeservices-cmyk:fix-queries-map-error

Conversation

@bookkeepingofficeservices-cmyk
Copy link

@bookkeepingofficeservices-cmyk bookkeepingofficeservices-cmyk commented Mar 5, 2026

Fix: TypeError - queries.map is not a function

Problem

When using Perplexica with local LLMs (especially Ollama), users encounter the following error during search operations:

TypeError: a.queries.map is not a function
    at Object.execute (.next/server/chunks/641.js:41:1486)

This error occurs when the AI model returns an invalid format for the queries parameter, causing the application to crash when trying to call .slice() or .map() on a non-array value.

Root Cause

The search action handlers (webSearch, socialSearch, academicSearch) assume that input.queries is always an array, but some AI models may return:

  • undefined
  • null
  • A string instead of an array
  • An object with unexpected structure

Solution

Added defensive validation checks before processing queries:

// Fix: Ensure queries is always an array
if (!input.queries || !Array.isArray(input.queries)) {
  console.error('Invalid queries format:', input);
  input.queries = [];
}

This ensures:

  1. The application doesn't crash on invalid input
  2. Errors are logged for debugging
  3. Search continues with an empty array (graceful degradation)

Files Changed

  • src/lib/agents/search/researcher/actions/webSearch.ts
  • src/lib/agents/search/researcher/actions/socialSearch.ts
  • src/lib/agents/search/researcher/actions/academicSearch.ts

Testing

Tested with:

  • Ollama (llama3.2:1b)
  • SearXNG backend
  • Various search queries in different languages

Impact

  • Prevents application crashes
  • Improves error handling and debugging
  • Maintains backward compatibility
  • No breaking changes

Related Issues

This fix addresses the common error reported by users when using local LLMs with Perplexica.


Summary by cubic

Prevents "TypeError: queries.map is not a function" by validating queries input and defaulting to an empty array so searches don’t crash. Sanitizes error logs and removes an accidentally committed Dockerfile.fixed.

  • Bug Fixes

    • Ensure input.queries is an array before use; default to []; log only safe metadata (hasQueries, type, isArray).
    • Applied to webSearch, socialSearch, and academicSearch actions.
  • Refactors

    • Remove temporary Dockerfile.fixed from the repo.

Written for commit cd38736. Summary will update on new commits.

- Added validation to ensure input.queries is always an array before calling .slice()
- Prevents 'queries.map is not a function' error when AI model returns invalid format
- Logs error for debugging when invalid format is detected
- Applies to webSearch, socialSearch, and academicSearch actions
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/lib/agents/search/researcher/actions/academicSearch.ts">

<violation number="1" location="src/lib/agents/search/researcher/actions/academicSearch.ts:35">
P2: Full payload logging in invalid-input path can leak sensitive user/model data to server logs.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- Replace full input object logging with safe metadata
- Only log query type information for debugging
- Addresses security concern from code review
@bookkeepingofficeservices-cmyk
Copy link
Author

Thanks for the security review! I've updated the code to avoid logging sensitive data. Now only logging safe metadata (query type, array status) for debugging purposes.

Changes made:

  • Replaced console.error('Invalid queries format:', input) with structured logging
  • Only log: hasQueries, queriesType, and isArray flags
  • No sensitive user or model data is exposed

Commit: cd5cc3c

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="Dockerfile.fixed">

<violation number="1" location="Dockerfile.fixed:1">
P2: Docker base image uses mutable `latest` tag, making builds non-reproducible and susceptible to unreviewed upstream changes.</violation>

<violation number="2" location="Dockerfile.fixed:9">
P2: The rebuild guard is ineffective: checking only `/home/perplexica-src` directory existence is always true after the preceding COPY commands, so `npm run build` runs unconditionally.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

This was a temporary test file and should not be part of the PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant