diegosouzapw/OmniRoute · error · Error

Local corpus search query is required

Error message

Local corpus search query is required

What it means

The normalized search query came out empty, so LocalCorpusIndex.search refuses to run. The caller passed a query that is missing, blank or whitespace-only; the guard fires before any index access. Sentinel validation on the public search entry point.

Solutions

  1. Return an empty result set instead of throwing for blank queries
  2. Validate the query at the API/MCP tool boundary
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/lib/localCorpus/index.ts:498 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/0c5af51226c170cb. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/localCorpus/index.ts:498

      chunks,
      truncated: this.truncated,
      lastIndexedAt:
        this.lastIndexedAt === null ? null : new Date(this.lastIndexedAt).toISOString(),
      limits: {
        maxFiles: this.limits.maxFiles,
        maxFileBytes: this.limits.maxFileBytes,
        maxTotalBytes: this.limits.maxTotalBytes,
        maxReadLines: this.limits.maxReadLines,
      },
    };
  }

  async search(
    query: string,
    options: { limit?: number; refresh?: boolean } = {}
  ): Promise<{ query: string; results: LocalCorpusSearchResult[]; status: LocalCorpusStatus }> {
    const normalizedQuery = query.trim().toLowerCase();
    if (!normalizedQuery) throw new Error("Local corpus search query is required");

    const stale =
      this.lastIndexedAt === null || Date.now() - this.lastIndexedAt >= this.limits.staleMs;
    if (options.refresh === true || stale) await this.refresh();

    const tokens = Array.from(new Set(normalizedQuery.split(/\s+/).filter(Boolean)));
    const limit = Math.min(positiveInteger(options.limit, 10), MAX_SEARCH_RESULTS);
    const results: LocalCorpusSearchResult[] = [];

    for (const file of this.files.values()) {
      for (const chunk of file.chunks) {
        const score = scoreChunk(chunk, normalizedQuery, tokens);
        if (score === 0) continue;
        results.push({
          relativePath: file.relativePath,
          startLine: chunk.startLine,
          endLine: chunk.endLine,
          score,

View on GitHub (pinned to a179ffed5b)