Skip to content

Commit 1b5bee1

Browse files
committed
refactor: Improve UUID error handling in indexing
1 parent c19d1ed commit 1b5bee1

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

src/lib/repository.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,14 @@ async function indexCommitsAndDiffs(
567567
);
568568

569569
try {
570-
const commitVector = await llmProvider.generateEmbedding(commitTextToEmbed);
571-
const commitPayload: CommitInfoPayload = {
570+
// === Commit Info ID Generation and Embedding ===
571+
if (!commit.oid || typeof commit.oid !== 'string') {
572+
logger.error(`Skipping commit due to invalid OID for ID generation. Commit: ${JSON.stringify(commit)}`);
573+
continue;
574+
}
575+
// Generate commit ID first
576+
const commitPointId = uuidv5(`commit:${String(repoPath)}:${String(commit.oid)}`, CODECOMPASS_NAMESPACE);
577+
const commitPayload: CommitInfoPayload = { // Define payload before embedding attempt
572578
dataType: 'commit_info',
573579
commit_oid: commit.oid,
574580
commit_message: commit.message,
@@ -609,8 +615,14 @@ async function indexCommitsAndDiffs(
609615
const diffContextualText = preprocessText(`Diff for ${changedFile.path} in commit ${commit.oid} (type: ${changedFile.type}):\n${diffChunk}`);
610616

611617
try {
612-
const diffVector = await llmProvider.generateEmbedding(diffContextualText);
613-
const diffPayload: DiffChunkPayload = {
618+
// === Diff Chunk ID Generation and Embedding ===
619+
if (!commit.oid || typeof commit.oid !== 'string' || !changedFile.path || typeof changedFile.path !== 'string') {
620+
logger.error(`Skipping diff chunk due to invalid commit OID or changed file path for ID generation. Commit OID: ${commit.oid}, FilePath: ${changedFile.path}`);
621+
continue;
622+
}
623+
// Generate diff ID first
624+
const diffPointId = uuidv5(`diff:${String(repoPath)}:${String(commit.oid)}:${String(changedFile.path)}:chunk:${i}`, CODECOMPASS_NAMESPACE);
625+
const diffPayload: DiffChunkPayload = { // Define payload before embedding
614626
dataType: 'diff_chunk',
615627
commit_oid: commit.oid,
616628
filepath: changedFile.path,
@@ -621,19 +633,20 @@ async function indexCommitsAndDiffs(
621633
repositoryPath: repoPath, // Optional
622634
};
623635
pointsToUpsert.push({
624-
// Generate UUID for diff chunk pointId
625-
id: uuidv5(`diff:${repoPath}:${commit.oid}:${changedFile.path}:chunk:${i}`, CODECOMPASS_NAMESPACE),
626-
vector: diffVector,
636+
id: diffPointId,
637+
// Now attempt embedding
638+
vector: await llmProvider.generateEmbedding(diffContextualText), // Embedding done here
627639
payload: diffPayload,
628640
});
629641
} catch (embedError) {
630-
logger.error(`Failed to generate embedding for diff chunk of ${changedFile.path} in commit ${commit.oid}`, { error: embedError instanceof Error ? embedError.message : String(embedError) });
642+
// This catch block will now primarily catch errors from llmProvider.generateEmbedding for diffs
643+
logger.error(`Failed to process or generate embedding for diff chunk of ${changedFile.path} in commit ${commit.oid}`, { error: embedError instanceof Error ? embedError.message : String(embedError) });
631644
// Continue to next chunk/file
632645
}
633646
}
634647
}
635648
}
636-
649+
637650
// Batch upsert periodically
638651
if (pointsToUpsert.length >= configService.QDRANT_BATCH_UPSERT_SIZE) {
639652
logger.info(`Upserting batch of ${pointsToUpsert.length} commit/diff points...`);

0 commit comments

Comments
 (0)