From 3c4f4dea315ea8831e40185e55840a63ea0f8cec Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 13 Aug 2024 18:13:36 -0700 Subject: [PATCH] extract functions responsible for errors --- core/core.ts | 1 + core/index.d.ts | 1 + core/indexing/CodebaseIndexer.ts | 5 ++++- core/util/extractMinimalStackTraceInfo.ts | 16 ++++++++++++++++ extensions/vscode/src/webviewProtocol.ts | 2 ++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 core/util/extractMinimalStackTraceInfo.ts diff --git a/core/core.ts b/core/core.ts index 340008cdb..d3ff7bf36 100644 --- a/core/core.ts +++ b/core/core.ts @@ -695,6 +695,7 @@ export class Core { "indexing_error", { error: update.desc, + stack: update.debugInfo, }, false, ); diff --git a/core/index.d.ts b/core/index.d.ts index 3fcb08fa1..8ce83c6f7 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -39,6 +39,7 @@ export interface IndexingProgressUpdate { desc: string; shouldClearIndexes?: boolean; status: "loading" | "indexing" | "done" | "failed" | "paused" | "disabled"; + debugInfo?: string; } export type PromptTemplate = diff --git a/core/indexing/CodebaseIndexer.ts b/core/indexing/CodebaseIndexer.ts index 33108c40e..293129627 100644 --- a/core/indexing/CodebaseIndexer.ts +++ b/core/indexing/CodebaseIndexer.ts @@ -1,6 +1,8 @@ +import * as fs from "fs/promises"; import { ConfigHandler } from "../config/ConfigHandler.js"; import { IContinueServerClient } from "../continueServer/interface.js"; import { IDE, IndexTag, IndexingProgressUpdate } from "../index.js"; +import { extractMinimalStackTraceInfo } from "../util/extractMinimalStackTraceInfo.js"; import { getIndexSqlitePath, getLanceDbPath } from "../util/paths.js"; import { ChunkCodebaseIndex } from "./chunk/ChunkCodebaseIndex.js"; import { CodeSnippetsCodebaseIndex } from "./CodeSnippetsIndex.js"; @@ -13,7 +15,6 @@ import { RefreshIndexResults, } from "./types.js"; import { walkDirAsync } from "./walkDir.js"; -import * as fs from "fs/promises"; export class PauseToken { constructor(private _paused: boolean) {} @@ -259,6 +260,7 @@ export class CodebaseIndexer { progress: 0, desc: `Indexing failed: ${err}`, status: "failed", + debugInfo: extractMinimalStackTraceInfo((err as any)?.stack), }; } @@ -282,6 +284,7 @@ export class CodebaseIndexer { desc: errMsg, status: "failed", shouldClearIndexes, + debugInfo: extractMinimalStackTraceInfo(err.stack), }; } diff --git a/core/util/extractMinimalStackTraceInfo.ts b/core/util/extractMinimalStackTraceInfo.ts new file mode 100644 index 000000000..a2fa226de --- /dev/null +++ b/core/util/extractMinimalStackTraceInfo.ts @@ -0,0 +1,16 @@ +/** + * It's helpful to know what functions errors occur in, but absolute + * file paths are sensitive information, so we want to remove them. + * @param stack The stack trace to extract minimal information from. + * @returns A string containing the minimal stack trace information. + */ +export function extractMinimalStackTraceInfo(stack: unknown): string { + if (typeof stack !== "string") return ""; + const lines = stack.split("\n"); + const minimalLines = lines.filter((line) => { + return line.trimStart().startsWith("at ") && !line.includes("node_modules"); + }); + return minimalLines + .map((line) => line.trimStart().replace("at ", "").split(" (").slice(0, 1)) + .join(", "); +} diff --git a/extensions/vscode/src/webviewProtocol.ts b/extensions/vscode/src/webviewProtocol.ts index f515995b8..eed3d15a0 100644 --- a/extensions/vscode/src/webviewProtocol.ts +++ b/extensions/vscode/src/webviewProtocol.ts @@ -1,4 +1,5 @@ import { FromWebviewProtocol, ToWebviewProtocol } from "core/protocol"; +import { extractMinimalStackTraceInfo } from "core/util/extractMinimalStackTraceInfo"; import { Message } from "core/util/messenger"; import { Telemetry } from "core/util/posthog"; import fs from "node:fs"; @@ -159,6 +160,7 @@ export class VsCodeWebviewProtocol { messageType: msg.messageType, errorMsg: message.split("\n\n")[0], + stack: extractMinimalStackTraceInfo(e.stack), }, false, );