{"record":{"id":"2a01c7e7559cb2bb","repo":"abhigyanpatwari/GitNexus","slug":"search-failed","errorCode":null,"errorMessage":"Search failed","messagePattern":"Search failed","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"gitnexus/src/server/api.ts","lineNumber":1562,"sourceCode":"                  .filter((p: any) => p.id && p.label);\n              }\n\n              return { ...r, ...enrichment };\n            }),\n          );\n\n          return { searchResults: enriched, ftsAvailable };\n        },\n        readOnlyFtsOptions(skipFts),\n      );\n      const response: any = { results: results.searchResults ?? results };\n      if (results.ftsAvailable === false) {\n        response.warning = ftsDegradedWarning(undefined, ftsDisabledReason);\n      }\n      res.json(response);\n    } catch (err: any) {\n      if (sendStorageRequirementHttp(err, res)) return;\n      res.status(500).json(httpErrorBody(err, 'Search failed'));\n    }\n  });\n\n  // Read file — with path traversal guard\n  // Rate-limited (CodeQL js/missing-rate-limiting): per-request fs.readFile.\n  app.get('/api/file', createRouteLimiter(), async (req, res) => {\n    try {\n      const entry = await resolveRepo(requestedRepo(req));\n      if (!entry) {\n        res.status(404).json({ error: 'Repository not found' });\n        return;\n      }\n      await handleFileRequest(req, res, entry.path, await getSourceAvailability(entry));\n    } catch (err: any) {\n      if (sendStorageRequirementHttp(err, res)) return;\n      res.status(500).json({ error: err.message || 'Failed to read file' });\n    }\n  });","sourceCodeStart":1544,"sourceCodeEnd":1580,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/server/api.ts#L1544-L1580","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the error body's message/detail for the underlying cause","Check the response warning about ftsAvailable/ftsDegraded — if FTS is degraded, re-run `gitnexus analyze` to rebuild the index","Verify the repo's .gitnexus storage is intact and no other process is writing to it","Retry the search; if persistent, check server logs for the stack trace"],"exampleFix":"// before: search against a corrupted index\ncurl 'localhost:4747/api/search?q=foo' // 500 { error: 'Search failed' }\n\n// after: rebuild the index\ncd my-repo && gitnexus analyze --index-only\ncurl 'localhost:4747/api/search?q=foo' // 200","handlingStrategy":"fallback","validationCode":"const repos = await (await fetch('/api/repos')).json();\nconst repo = repos.find(r => r.name === name);\nif (repo && repo.ftsAvailable === false) console.warn('FTS degraded; rebuild index');","typeGuard":null,"tryCatchPattern":"const res = await fetch(`/api/search?q=${encodeURIComponent(q)}`);\nif (res.status === 500) {\n  const body = await res.json();\n  // fall back to local grep or retry after re-index\n  console.warn('Search failed:', body.error);\n}","preventionTips":["Inspect the ftsAvailable/warning fields on successful search responses to detect degradation early","Rebuild the index after interrupted analyze runs","Avoid concurrent writes to the repo's storage while searching"],"tags":["http-500","search","fts","index"],"backgroundTag":"database-query-failed","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-09-15T23:29:44.066Z","contentChangedAt":"2026-09-15T23:29:44.066Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}