extract functions responsible for errors

This commit is contained in:
Nate Sesti 2024-08-13 18:13:36 -07:00
parent 296ee4f9c5
commit 3c4f4dea31
5 changed files with 24 additions and 1 deletions

View file

@ -695,6 +695,7 @@ export class Core {
"indexing_error",
{
error: update.desc,
stack: update.debugInfo,
},
false,
);

1
core/index.d.ts vendored
View file

@ -39,6 +39,7 @@ export interface IndexingProgressUpdate {
desc: string;
shouldClearIndexes?: boolean;
status: "loading" | "indexing" | "done" | "failed" | "paused" | "disabled";
debugInfo?: string;
}
export type PromptTemplate =

View file

@ -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),
};
}

View file

@ -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(", ");
}

View file

@ -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,
);