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

Function fail

shared/assert.ts:47–67  ·  view source on GitHub ↗
(fail_message: string, user_message: string | undefined, args: any[])

Source from the content-addressed store, hash-verified

45}
46
47function fail(fail_message: string, user_message: string | undefined, args: any[]): never {
48 // Assertions will look like:
49 // Assertion failed
50 // Assertion failed: Foobar
51 // Assertion failed: Foobar, [{"foo": "bar"}]
52 let assert_line = fail_message;
53 if (user_message) {
54 assert_line += `: ${user_message}`;
55 }
56 if (args.length > 0) {
57 try {
58 assert_line += ', ' + JSON.stringify(args);
59 } catch {}
60 }
61
62 const diagnostic = get_diagnostic();
63 if (diagnostic) {
64 throw new Error(assert_line + `, at ${diagnostic.file}:${diagnostic.line}`);
65 }
66 throw new Error(assert_line);
67}
68
69export function assert(c: unknown, message?: string, ...extra_info: any[]): asserts c {
70 if (!c) {

Callers 3

assertFunction · 0.70
unwrapFunction · 0.70
unwrapStringFunction · 0.70

Calls 1

get_diagnosticFunction · 0.70

Tested by

no test coverage detected