Skip to content

Commit cf6fc3d

Browse files
fix(web): Fix "repository not found for file: x" error (#761)
1 parent 4fecf40 commit cf6fc3d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Bumped AI SDK and associated packages version. [#752](https://github.com/sourcebot-dev/sourcebot/pull/752)
1212
- Bumped Node.js version to v24. [#753](https://github.com/sourcebot-dev/sourcebot/pull/753)
1313

14+
### Fixed
15+
- Fixed "Repository not found for file: x" error when searching in orphaned shards. [#761](https://github.com/sourcebot-dev/sourcebot/pull/761)
16+
1417
## [4.10.12] - 2026-01-16
1518

1619
### Changed

packages/web/src/features/search/zoektSearcher.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { createLogger, env } from "@sourcebot/shared";
1717
import path from 'path';
1818
import { isBranchQuery, QueryIR, someInQueryIR } from './ir';
1919
import { RepositoryInfo, SearchResponse, SearchResultFile, SearchStats, SourceRange, StreamedSearchErrorResponse, StreamedSearchResponse } from "./types";
20+
import { captureEvent } from "@/lib/posthog";
2021

2122
const logger = createLogger("zoekt-searcher");
2223

@@ -383,9 +384,17 @@ const transformZoektSearchResponse = async (response: ZoektGrpcSearchResponse, r
383384
const repoId = getRepoIdForFile(file);
384385
const repo = reposMapCache.get(repoId);
385386

386-
// This should never happen.
387+
// This can happen when a shard exists for a repository that does not exist in the database.
388+
// In this case, issue a error message and skip the file.
389+
// @see: https://github.com/sourcebot-dev/sourcebot/issues/669
387390
if (!repo) {
388-
throw new Error(`Repository not found for file: ${file.file_name}`);
391+
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...`;
392+
393+
logger.error(errorMessage);
394+
Sentry.captureMessage(errorMessage);
395+
captureEvent('wa_repo_not_found_for_zoekt_file', {});
396+
397+
return undefined;
389398
}
390399

391400
// @todo: address "file_name might not be a valid UTF-8 string" warning.

packages/web/src/lib/posthogEvents.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ export type PosthogEventMap = {
185185
durationMs: number,
186186
},
187187
//////////////////////////////////////////////////////////////////
188+
wa_repo_not_found_for_zoekt_file: {},
189+
//////////////////////////////////////////////////////////////////
188190
api_code_search_request: {
189191
source: string;
190192
type: 'streamed' | 'blocking';

0 commit comments

Comments
 (0)