MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / parse

Function parse

shared/stacktrace.ts:42–174  ·  view source on GitHub ↗
(err: Error)

Source from the content-addressed store, hash-verified

40}
41
42export function parse(err: Error) {
43 if (!err.stack) {
44 return [];
45 }
46
47 let format: TraceFormat;
48
49 if (typeof window === 'undefined') {
50 // node
51 format = TraceFormat.V8;
52 } else {
53 if (navigator.userAgent.includes('AppleWebKit')) {
54 // Just going with V8 for now...
55 format = TraceFormat.V8;
56 } else if ((window as any).chrome) {
57 format = TraceFormat.V8;
58 } else if (navigator.userAgent.toLowerCase().includes('firefox')) {
59 format = TraceFormat.Firefox;
60 } else {
61 // We'll just default to V8 for now...
62 format = TraceFormat.V8;
63 }
64 }
65 if (format === TraceFormat.V8) {
66 return err.stack
67 .split('\n')
68 .slice(1)
69 .map((line): StackFrame | undefined => {
70 if (/^\s*-{4,}$/.test(line)) {
71 return {
72 fileName: line,
73 };
74 }
75
76 const lineMatch = line.match(/at (?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/);
77 if (!lineMatch) {
78 return undefined;
79 }
80
81 let object: string | undefined;
82 let method: string | undefined;
83 let functionName: string | undefined;
84 let typeName: string | undefined;
85 let methodName: string | undefined;
86 const isNative = lineMatch[5] === 'native';
87
88 if (lineMatch[1]) {
89 functionName = lineMatch[1];
90 let methodStart = functionName.lastIndexOf('.');
91 if (functionName[methodStart - 1] === '.') methodStart--;
92 if (methodStart > 0) {
93 object = functionName.substring(0, methodStart);
94 method = functionName.substring(methodStart + 1);
95 const objectEnd = object.indexOf('.Module');
96 if (objectEnd > 0) {
97 functionName = functionName.substring(objectEnd + 1);
98 object = object.substring(0, objectEnd);
99 }

Callers 2

get_diagnosticFunction · 0.70
SentryCaptureFunction · 0.50

Calls 2

testMethod · 0.80
matchMethod · 0.80

Tested by

no test coverage detected