abhigyanpatwari/GitNexus · error

Search failed

Error message

Search failed

What it means

A 500 response from the search endpoint (GET /api/search). When the search handler throws and the error is not a storage-requirement error (which would be mapped to 410), the server wraps it with httpErrorBody using the label 'Search failed'.

Solutions

  1. Read the error body's message/detail for the underlying cause
  2. Check the response warning about ftsAvailable/ftsDegraded — if FTS is degraded, re-run `gitnexus analyze` to rebuild the index
  3. Verify the repo's .gitnexus storage is intact and no other process is writing to it
  4. Retry the search; if persistent, check server logs for the stack trace

Example fix

// before: search against a corrupted index
curl 'localhost:4747/api/search?q=foo' // 500 { error: 'Search failed' }

// after: rebuild the index
cd my-repo && gitnexus analyze --index-only
curl 'localhost:4747/api/search?q=foo' // 200
Defensive patterns

Strategy: fallback

Validate before calling

const repos = await (await fetch('/api/repos')).json();
const repo = repos.find(r => r.name === name);
if (repo && repo.ftsAvailable === false) console.warn('FTS degraded; rebuild index');

Try / catch

const res = await fetch(`/api/search?q=${encodeURIComponent(q)}`);
if (res.status === 500) {
  const body = await res.json();
  // fall back to local grep or retry after re-index
  console.warn('Search failed:', body.error);
}

Prevention

When it happens

Trigger: GET /api/search when the search operation throws unexpectedly — corrupted or mid-write FTS index, repo resolution failure not tied to storage retention, or an internal error in the ranking/query pipeline.

Common situations: Happens after an interrupted analyze leaves a partially written FTS index, when querying a repo whose storage was concurrently modified, or from a malformed internal state not caught by input validation.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@ac9a4e9abd (2026-09-15). Data as JSON: /api/errors/2a01c7e7559cb2bb. Report an issue: GitHub.

Appendix: source

Thrown at gitnexus/src/server/api.ts:1562

                  .filter((p: any) => p.id && p.label);
              }

              return { ...r, ...enrichment };
            }),
          );

          return { searchResults: enriched, ftsAvailable };
        },
        readOnlyFtsOptions(skipFts),
      );
      const response: any = { results: results.searchResults ?? results };
      if (results.ftsAvailable === false) {
        response.warning = ftsDegradedWarning(undefined, ftsDisabledReason);
      }
      res.json(response);
    } catch (err: any) {
      if (sendStorageRequirementHttp(err, res)) return;
      res.status(500).json(httpErrorBody(err, 'Search failed'));
    }
  });

  // Read file — with path traversal guard
  // Rate-limited (CodeQL js/missing-rate-limiting): per-request fs.readFile.
  app.get('/api/file', createRouteLimiter(), async (req, res) => {
    try {
      const entry = await resolveRepo(requestedRepo(req));
      if (!entry) {
        res.status(404).json({ error: 'Repository not found' });
        return;
      }
      await handleFileRequest(req, res, entry.path, await getSourceAvailability(entry));
    } catch (err: any) {
      if (sendStorageRequirementHttp(err, res)) return;
      res.status(500).json({ error: err.message || 'Failed to read file' });
    }
  });

View on GitHub (pinned to ac9a4e9abd)