Skip to content

Commit f87d0a8

Browse files
committed
Fixed assert deriving error message via a function
1 parent 3ca9221 commit f87d0a8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/realm/src/assert.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ export function assert(
3131
err?: string | Error | (() => undefined | string | Error),
3232
): asserts condition {
3333
if (!condition) {
34-
const errValue = typeof err === "function" ? err() : err;
35-
if (errValue instanceof Error) {
34+
// Call any function to generate the error lazily
35+
err = typeof err === "function" ? err() : err;
36+
if (err instanceof Error) {
3637
throw err;
3738
} else if (typeof err === "string" || typeof err === "undefined") {
38-
throw new AssertionError(errValue);
39+
throw new AssertionError(err);
3940
} else {
4041
throw new Error("Expected err to be an Err, string, undefined or a function returning either.");
4142
}

0 commit comments

Comments
 (0)