-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathassert.ts
27 lines (25 loc) · 926 Bytes
/
assert.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import * as vscode from "vscode";
let assertionFailureReported = false;
/**
* Asserts that the given value is true.
*/
export function assert(value: boolean): asserts value {
if (!value) {
debugger; // eslint-disable-line no-debugger
if (!assertionFailureReported) {
// Only report one assertion failure, to avoid spamming the
// user with error messages.
assertionFailureReported = true;
// Log an `Error` object which will include the stack trace
// eslint-disable-next-line no-console
console.error(new Error("Assertion violated."));
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.window.showErrorMessage(
"Assertion violated. This is a programming error.\n" +
"Please file a bug at " +
"https://github.com/bazelbuild/vscode-bazel/issues",
);
}
throw new Error("Assertion violated.");
}
}