Elffuss BraidHub

kikocis/continue public

3ff29c567dd0 · 1.1 KiBRawPermalink
1/**
2 * It's helpful to know what functions errors occur in, but absolute
3 * file paths are sensitive information, so we want to remove them.
4 * @param stack The stack trace to extract minimal information from.
5 * @returns A string containing the minimal stack trace information.
6 */
7export function extractMinimalStackTraceInfo(stack: unknown): string {
8 if (typeof stack !== "string") {
9 return "";
10 }
11 const lines = stack
12 .trim()
13 .split("\n")
14 .map((line) => line.trim());
15 const minimalLines = lines.filter((line) => {
16 return (
17 line.startsWith("at ") &&
18 !line.includes("node_modules") &&
19 !line.includes("node:internal")
20 );
21 });
22 return minimalLines
23 .map((line) => line.replace("at ", "").split(" (").slice(0, 1))
24 .flatMap((parts) =>
25 parts.map(
26 // to be safe, remove any lingering paths - anonymous function case
27 (part) =>
28 part.replace(/(?:[A-Za-z]:[\\/]|[\\/])[^\n]*?:\d+:\d+/g, "").trim(),
29 ),
30 )
31 .filter((part) => !!part) // remove empty string parts (anonymous functions case)
32 .join(", ");
33}