diff --git a/CHANGELOG.md b/CHANGELOG.md index fb80ecf0f..76dcd736d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bumped AI SDK and associated packages version. [#752](https://github.com/sourcebot-dev/sourcebot/pull/752) - Bumped Node.js version to v24. [#753](https://github.com/sourcebot-dev/sourcebot/pull/753) +### Fixed +- Fixed "Repository not found for file: x" error when searching in orphaned shards. [#761](https://github.com/sourcebot-dev/sourcebot/pull/761) + ## [4.10.12] - 2026-01-16 ### Changed diff --git a/packages/web/src/features/search/zoektSearcher.ts b/packages/web/src/features/search/zoektSearcher.ts index 5bdea8bce..61cefdcf1 100644 --- a/packages/web/src/features/search/zoektSearcher.ts +++ b/packages/web/src/features/search/zoektSearcher.ts @@ -17,6 +17,7 @@ import { createLogger, env } from "@sourcebot/shared"; import path from 'path'; import { isBranchQuery, QueryIR, someInQueryIR } from './ir'; import { RepositoryInfo, SearchResponse, SearchResultFile, SearchStats, SourceRange, StreamedSearchErrorResponse, StreamedSearchResponse } from "./types"; +import { captureEvent } from "@/lib/posthog"; const logger = createLogger("zoekt-searcher"); @@ -383,9 +384,17 @@ const transformZoektSearchResponse = async (response: ZoektGrpcSearchResponse, r const repoId = getRepoIdForFile(file); const repo = reposMapCache.get(repoId); - // This should never happen. + // This can happen when a shard exists for a repository that does not exist in the database. + // In this case, issue a error message and skip the file. + // @see: https://github.com/sourcebot-dev/sourcebot/issues/669 if (!repo) { - throw new Error(`Repository not found for file: ${file.file_name}`); + const errorMessage = `Unable to find repository "${file.repository}" in database for file "${file.file_name}". This can happen when a search shard exists for a repository that does not exist in the database. See https://github.com/sourcebot-dev/sourcebot/issues/669 for more details. Skipping file...`; + + logger.error(errorMessage); + Sentry.captureMessage(errorMessage); + captureEvent('wa_repo_not_found_for_zoekt_file', {}); + + return undefined; } // @todo: address "file_name might not be a valid UTF-8 string" warning. diff --git a/packages/web/src/lib/posthogEvents.ts b/packages/web/src/lib/posthogEvents.ts index 36df22a71..eee32bc05 100644 --- a/packages/web/src/lib/posthogEvents.ts +++ b/packages/web/src/lib/posthogEvents.ts @@ -185,6 +185,8 @@ export type PosthogEventMap = { durationMs: number, }, ////////////////////////////////////////////////////////////////// + wa_repo_not_found_for_zoekt_file: {}, + ////////////////////////////////////////////////////////////////// api_code_search_request: { source: string; type: 'streamed' | 'blocking';