MCPcopy Index your code
hub / github.com/midrender/revideo / resolveStackTrace

Function resolveStackTrace

packages/ui/src/utils/sourceMaps.ts:52–128  ·  view source on GitHub ↗
(
  stack: string,
  firstOnly?: boolean,
)

Source from the content-addressed store, hash-verified

50 stack: string,
51): Promise<StackTraceEntry[]>;
52export async function resolveStackTrace(
53 stack: string,
54 firstOnly?: boolean,
55): Promise<StackTraceEntry[] | StackTraceEntry> {
56 const result: StackTraceEntry[] = [];
57 for (const textLine of stack.split('\n')) {
58 const match = textLine.match(StackTraceRegex);
59 if (!match) continue;
60 const [, functionName, uri, line, column] = match;
61 const parsed = new URL(uri);
62 const file = parsed.pathname;
63 const directory = file.split('/').slice(0, -1).join('/') + '/';
64 const entry: StackTraceEntry = {
65 file,
66 uri,
67 line: parseInt(line),
68 column: parseInt(column),
69 isExternal: ExternalFileRegex.test(file),
70 functionName: functionName?.trim(),
71 };
72
73 if (!entry.isExternal) {
74 try {
75 const sourceMap = await getSourceMap(file, parsed.search);
76 const position = sourceMap.originalPositionFor(entry);
77 if (position.line === null || position.column === null) {
78 entry.isExternal = true;
79 } else {
80 const source =
81 position.source[0] === '/'
82 ? position.source
83 : directory + position.source;
84
85 entry.file = source;
86 entry.line = position.line;
87 entry.column = position.column;
88 entry.source = position.source;
89 entry.sourceMap = sourceMap;
90
91 if (firstOnly) {
92 return entry;
93 }
94 }
95 } catch (e) {
96 entry.isExternal = true;
97 }
98 }
99
100 result.push(entry);
101
102 if (entry.sourceMap?.raw?.includeMap) {
103 const includeMap: Record<string, [string, number]> =
104 entry.sourceMap.raw.includeMap;
105 let current = entry;
106 while (current.source in includeMap) {
107 const [path, line] = includeMap[current.source];
108 const file = directory + path;
109 current = {

Callers 2

LogFunction · 0.90
findAndOpenFirstUserFileFunction · 0.85

Calls 2

getSourceMapFunction · 0.85
splitMethod · 0.45

Tested by

no test coverage detected