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

Function fail

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

Source from the content-addressed store, hash-verified

85}
86
87function fail(fail_message: string, user_message: string | undefined, args: any[]): never {
88 // Assertions will look like:
89 // Assertion failed
90 // Assertion failed: Foobar
91 // Assertion failed: Foobar, [{"foo": "bar"}]
92 // Assertion failed: Foobar, [{"foo": "bar"}], at `assert(x.foo.length < 2, "Foobar", x)`
93 let assert_line = fail_message;
94 if (user_message) {
95 assert_line += `: ${user_message}`;
96 }
97 if (args.length > 0) {
98 try {
99 assert_line += ', ' + JSON.stringify(args);
100 } catch {}
101 }
102
103 const diagnostic = get_diagnostic();
104 if (diagnostic) {
105 throw new Error(assert_line + `, at ${diagnostic.file}:${diagnostic.line} \`${diagnostic.src}\``);
106 }
107 throw new Error(assert_line);
108}
109
110// Using `unknown` instead of generic implementation due to:
111// https://github.com/microsoft/TypeScript/issues/60130

Callers 3

assertFunction · 0.70
unwrapFunction · 0.70
unwrapStringFunction · 0.70

Calls 1

get_diagnosticFunction · 0.70

Tested by

no test coverage detected