We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3ca9221 commit f87d0a8Copy full SHA for f87d0a8
packages/realm/src/assert.ts
@@ -31,11 +31,12 @@ export function assert(
31
err?: string | Error | (() => undefined | string | Error),
32
): asserts condition {
33
if (!condition) {
34
- const errValue = typeof err === "function" ? err() : err;
35
- if (errValue instanceof Error) {
+ // Call any function to generate the error lazily
+ err = typeof err === "function" ? err() : err;
36
+ if (err instanceof Error) {
37
throw err;
38
} else if (typeof err === "string" || typeof err === "undefined") {
- throw new AssertionError(errValue);
39
+ throw new AssertionError(err);
40
} else {
41
throw new Error("Expected err to be an Err, string, undefined or a function returning either.");
42
}
0 commit comments