MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / parseStackFrame

Function parseStackFrame

src/debug/stack_trace.ts:11–58  ·  view source on GitHub ↗
(message: string)

Source from the content-addressed store, hash-verified

9}
10
11export function parseStackFrame(message: string): MessageWithUriData | undefined {
12 // Messages over 1000 characters are unlikely to be stack frames, so short-cut
13 // and assume no match.
14 if (!message || message.length > maxStackFrameMessageLength)
15 return undefined;
16
17 const match = stackFramePattern.exec(message);
18 if (match) {
19 const prefix = message.substr(0, match.index).trim();
20 const suffix = (match[4] || "").trim();
21 let col = match[3] !== undefined ? parseInt(match[3]) : undefined;
22 let line = match[2] !== undefined ? parseInt(match[2]) : undefined;
23
24 // Handle some common line/col in text that are not in the usual format we can extract, for ex.
25 // Failed assertion: line ${line} pos ${col}
26 if (!line) {
27 const lineMatch = linePattern.exec(message);
28 if (lineMatch)
29 line = parseInt(lineMatch[1]);
30 }
31 if (!col) {
32 const colMatch = colPattern.exec(message);
33 if (colMatch)
34 col = parseInt(colMatch[1]);
35 }
36
37 // Only consider this a stack frame if this has either a prefix or suffix, otherwise
38 // it's likely just a printed filename or a line like "Launching lib/foo.dart on ...".
39 const isStackFrame = !!prefix !== !!suffix;
40
41 // Text should only be replaced if there was a line/col and only one of prefix/suffix, to avoid
42 // replacing user prints of filenames or text like "Launching lib/foo.dart on Chrome".
43 const textReplacement = (isStackFrame && line && col)
44 ? (prefix || suffix)
45 : undefined;
46 const text = `${textReplacement || message}`.trim();
47
48
49 return {
50 col,
51 isStackFrame,
52 line,
53 sourceUri: match[1],
54 text,
55 } as MessageWithUriData;
56 }
57 return undefined;
58}
59
60interface MessageWithUriData {
61 col: number | undefined;

Callers 2

logToUserFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected