(fail_message: string, user_message: string | undefined, args: any[])
| 85 | } |
| 86 | |
| 87 | function 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 |
no test coverage detected