diff --git a/core/indexing/CodeSnippetsIndex.ts b/core/indexing/CodeSnippetsIndex.ts index 884411491..da0be7506 100644 --- a/core/indexing/CodeSnippetsIndex.ts +++ b/core/indexing/CodeSnippetsIndex.ts @@ -104,10 +104,16 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { for (let i = 0; i < results.compute.length; i++) { const compute = results.compute[i]; - const snippets = await this.getSnippetsInFile( - compute.path, - await this.ide.readFile(compute.path), - ); + + let snippets: (ChunkWithoutID & { title: string })[] = []; + try { + snippets = await this.getSnippetsInFile( + compute.path, + await this.ide.readFile(compute.path), + ); + } catch (e) { + // If can't parse, assume malformatted code + } // Add snippets to sqlite for (const snippet of snippets) { diff --git a/core/indexing/LanceDbIndex.ts b/core/indexing/LanceDbIndex.ts index 33fdf77b2..69b7e9f58 100644 --- a/core/indexing/LanceDbIndex.ts +++ b/core/indexing/LanceDbIndex.ts @@ -98,6 +98,12 @@ export class LanceDbIndex implements CodebaseIndex { chunks.map((c) => c.content), ); + if (embeddings.some((emb) => emb === undefined)) { + throw new Error( + `Failed to generate embedding for ${chunks[0]?.filepath} with provider: ${this.embeddingsProvider.id}`, + ); + } + // Create row format for (let j = 0; j < chunks.length; j++) { const progress = (i + j / chunks.length) / items.length; diff --git a/core/indexing/indexCodebase.ts b/core/indexing/indexCodebase.ts index 1e6040fc1..98ed0b213 100644 --- a/core/indexing/indexCodebase.ts +++ b/core/indexing/indexCodebase.ts @@ -88,21 +88,21 @@ export class CodebaseIndexer { const repoName = await this.ide.getRepoName(directory); let completedIndexes = 0; - try { - for (let codebaseIndex of indexesToBuild) { - // TODO: IndexTag type should use repoName rather than directory - const tag: IndexTag = { - directory, - branch, - artifactId: codebaseIndex.artifactId, - }; - const [results, markComplete] = await getComputeDeleteAddRemove( - tag, - { ...stats }, - (filepath) => this.ide.readFile(filepath), - repoName, - ); + for (let codebaseIndex of indexesToBuild) { + // TODO: IndexTag type should use repoName rather than directory + const tag: IndexTag = { + directory, + branch, + artifactId: codebaseIndex.artifactId, + }; + const [results, markComplete] = await getComputeDeleteAddRemove( + tag, + { ...stats }, + (filepath) => this.ide.readFile(filepath), + repoName, + ); + try { for await (let { progress, desc } of codebaseIndex.update( tag, results, @@ -136,9 +136,11 @@ export class CodebaseIndexer { workspaceDirs.length, desc: "Completed indexing " + codebaseIndex.artifactId, }; + } catch (e) { + console.warn( + `Error updating the ${codebaseIndex.artifactId} index: ${e}`, + ); } - } catch (e) { - console.warn("Error refreshing index: ", e); } completedDirs++;