Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

chore(frontend): Add `invariant` debugger statement for development (#5414)

Trevor Manzb7e308a476c3
diff --git a/frontend/src/utils/assertNever.ts b/frontend/src/utils/assertNever.ts
index 9900b48a80..009e3f0b79 100644
--- a/frontend/src/utils/assertNever.ts
+++ b/frontend/src/utils/assertNever.ts
@@ -1,11 +1,12 @@
/* Copyright 2024 Marimo. All rights reserved. */
+import { invariant } from "./invariant";
import { Logger } from "./Logger";
/**
* Type-safe exhaustiveness check for discriminated unions.
*/
export function assertNever(x: never): never {
- throw new Error(`Unexpected object: ${x}`);
+ invariant(false, `Unexpected object: ${x}`);
}
/**
diff --git a/frontend/src/utils/invariant.ts b/frontend/src/utils/invariant.ts
index ffad8f04f7..f21365eef2 100644
--- a/frontend/src/utils/invariant.ts
+++ b/frontend/src/utils/invariant.ts
@@ -27,6 +27,11 @@ export function invariant(
msg: string,
): asserts expression {
if (!expression) {
+ if (import.meta.env.DEV) {
+ // Triggers a breakpoint in development; stripped out in production builds.
+ // biome-ignore lint/suspicious/noDebugger: code block is stripped out in production builds
+ debugger; // eslint-disable-line no-debugger
+ }
throw new Error(msg);
}
}