diff --git a/core/indexing/chunk/chunk.ts b/core/indexing/chunk/chunk.ts index 97665ab03..48af77c38 100644 --- a/core/indexing/chunk/chunk.ts +++ b/core/indexing/chunk/chunk.ts @@ -1,5 +1,7 @@ -import { Chunk, ChunkWithoutID, IDE } from "../../index.js"; +import { Chunk, ChunkWithoutID } from "../../index.js"; import { countTokens, countTokensAsync } from "../../llm/countTokens.js"; +import { extractMinimalStackTraceInfo } from "../../util/extractMinimalStackTraceInfo.js"; +import { Telemetry } from "../../util/posthog.js"; import { supportedLanguages } from "../../util/treeSitter.js"; import { basicChunker } from "./basic.js"; import { codeChunker } from "./code.js"; @@ -28,8 +30,11 @@ async function* chunkDocumentWithoutId( yield chunk; } return; - } catch (e) { - // console.error(`Failed to parse ${filepath}: `, e); + } catch (e: any) { + Telemetry.capture("code_chunker_error", { + fileExtension: ext, + stack: extractMinimalStackTraceInfo(e.stack), + }); // falls back to basicChunker } } @@ -78,7 +83,11 @@ export async function* chunkDocument({ } } -export function shouldChunk(pathSep: string, filepath: string, contents: string): boolean { +export function shouldChunk( + pathSep: string, + filepath: string, + contents: string, +): boolean { if (contents.length > 1000000) { // if a file has more than 1m characters then skip it return false; @@ -89,4 +98,4 @@ export function shouldChunk(pathSep: string, filepath: string, contents: string) const basename = filepath.split(pathSep).pop(); // files without extensions are often binary files, skip it if so return basename?.includes(".") ?? false; -} \ No newline at end of file +} diff --git a/core/indexing/chunk/code.ts b/core/indexing/chunk/code.ts index 7e3fff2b3..be02fbb2a 100644 --- a/core/indexing/chunk/code.ts +++ b/core/indexing/chunk/code.ts @@ -232,8 +232,7 @@ export async function* codeChunker( const parser = await getParserForFile(filepath); if (parser === undefined) { - console.debug(`Failed to load parser for file ${filepath}: `); - return; + throw new Error(`Failed to load parser for file ${filepath}: `); } const tree = parser.parse(contents);