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

Function get_diagnostic

lib/assert.ts:64–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62
63// Explicitly export for testing purposes - not part of the public API
64export function get_diagnostic() {
65 const e = new Error();
66 const trace = parse(e);
67 if (trace.length >= 4) {
68 const invoker_frame = trace[3];
69 if (invoker_frame.fileName && invoker_frame.lineNumber) {
70 // Just out of an abundance of caution...
71 const relative = check_path(ce_base_directory, removeFileProtocol(invoker_frame.fileName));
72 if (relative) {
73 try {
74 const file = fs.readFileSync(invoker_frame.fileName, 'utf8');
75 const lines = file.split('\n');
76 return {
77 file: relative,
78 line: invoker_frame.lineNumber,
79 src: lines[invoker_frame.lineNumber - 1].trim(),
80 };
81 } catch {}
82 }
83 }
84 }
85}
86
87function fail(fail_message: string, user_message: string | undefined, args: any[]): never {
88 // Assertions will look like:

Callers 1

failFunction · 0.70

Calls 3

check_pathFunction · 0.85
removeFileProtocolFunction · 0.85
parseFunction · 0.70

Tested by

no test coverage detected