Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

[codex] Structure native view resolution failures (#3353)

Julius Marminge779c23748768
diff --git a/apps/mobile/src/features/diffs/nativeReviewDiffSurface.test.ts b/apps/mobile/src/features/diffs/nativeReviewDiffSurface.test.ts
index 65e753934..975bf7be1 100644
--- a/apps/mobile/src/features/diffs/nativeReviewDiffSurface.test.ts
+++ b/apps/mobile/src/features/diffs/nativeReviewDiffSurface.test.ts
@@ -58,10 +58,23 @@ describe("resolveNativeReviewDiffView", () => {
it("returns null when the view manager cannot be required", async () => {
setExpoViewConfigAvailable();
+ const cause = new Error("boom");
expoMocks.requireNativeView.mockImplementation(() => {
- throw new Error("boom");
+ throw cause;
});
+ const consoleError = vi.spyOn(console, "error").mockImplementation(() => undefined);
const { resolveNativeReviewDiffView } = await import("./nativeReviewDiffSurface");
+
+ expect(resolveNativeReviewDiffView()).toBeNull();
expect(resolveNativeReviewDiffView()).toBeNull();
+ expect(expoMocks.requireNativeView).toHaveBeenCalledTimes(1);
+ expect(consoleError).toHaveBeenCalledWith(
+ expect.objectContaining({
+ _tag: "NativeViewResolutionError",
+ nativeModuleName: "T3ReviewDiffSurface",
+ cause,
+ }),
+ );
+ expect(consoleError).toHaveBeenCalledTimes(1);
});
});
diff --git a/apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts b/apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts
index 4a6816634..7660a0477 100644
--- a/apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts
+++ b/apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts
@@ -2,6 +2,8 @@ import type { ComponentType } from "react";
import type { NativeSyntheticEvent, ViewProps } from "react-native";
import { requireNativeView } from "expo";
+import { NativeViewResolutionError } from "../../native/nativeViewResolutionError";
+
const NATIVE_REVIEW_DIFF_MODULE_NAME = "T3ReviewDiffSurface";
interface ExpoGlobalWithViewConfig {
@@ -128,6 +130,7 @@ export interface NativeReviewDiffViewProps extends ViewProps {
}
let cachedNativeReviewDiffView: ComponentType<NativeReviewDiffViewProps> | undefined;
+let nativeReviewDiffViewResolutionFailed = false;
function getExpoViewConfig(moduleName: string) {
return (globalThis as typeof globalThis & ExpoGlobalWithViewConfig).expo?.getViewConfig?.(
@@ -140,6 +143,10 @@ export function resolveNativeReviewDiffView(): ComponentType<NativeReviewDiffVie
return cachedNativeReviewDiffView;
}
+ if (nativeReviewDiffViewResolutionFailed) {
+ return null;
+ }
+
if (getExpoViewConfig(NATIVE_REVIEW_DIFF_MODULE_NAME) == null) {
return null;
}
@@ -148,7 +155,14 @@ export function resolveNativeReviewDiffView(): ComponentType<NativeReviewDiffVie
cachedNativeReviewDiffView = requireNativeView<NativeReviewDiffViewProps>(
NATIVE_REVIEW_DIFF_MODULE_NAME,
);
- } catch {
+ } catch (cause) {
+ nativeReviewDiffViewResolutionFailed = true;
+ console.error(
+ new NativeViewResolutionError({
+ nativeModuleName: NATIVE_REVIEW_DIFF_MODULE_NAME,
+ cause,
+ }),
+ );
return null;
}
diff --git a/apps/mobile/src/features/terminal/nativeTerminalModule.test.ts b/apps/mobile/src/features/terminal/nativeTerminalModule.test.ts
index c7418a525..5cb37cbb0 100644
--- a/apps/mobile/src/features/terminal/nativeTerminalModule.test.ts
+++ b/apps/mobile/src/features/terminal/nativeTerminalModule.test.ts
@@ -43,10 +43,23 @@ describe("resolveNativeTerminalSurfaceView", () => {
it("returns null when the view manager cannot be required", async () => {
setExpoViewConfigAvailable();
+ const cause = new Error("boom");
expoMocks.requireNativeView.mockImplementation(() => {
- throw new Error("boom");
+ throw cause;
});
+ const consoleError = vi.spyOn(console, "error").mockImplementation(() => undefined);
const { resolveNativeTerminalSurfaceView } = await import("./nativeTerminalModule");
+
+ expect(resolveNativeTerminalSurfaceView()).toBeNull();
expect(resolveNativeTerminalSurfaceView()).toBeNull();
+ expect(expoMocks.requireNativeView).toHaveBeenCalledTimes(1);
+ expect(consoleError).toHaveBeenCalledWith(
+ expect.objectContaining({
+ _tag: "NativeViewResolutionError",
+ nativeModuleName: "T3TerminalSurface",
+ cause,
+ }),
+ );
+ expect(consoleError).toHaveBeenCalledTimes(1);
});
});
diff --git a/apps/mobile/src/features/terminal/nativeTerminalModule.ts b/apps/mobile/src/features/terminal/nativeTerminalModule.ts
index c4686a38b..e5b1f6300 100644
--- a/apps/mobile/src/features/terminal/nativeTerminalModule.ts
+++ b/apps/mobile/src/features/terminal/nativeTerminalModule.ts
@@ -2,6 +2,8 @@ import type { ComponentType } from "react";
import type { NativeSyntheticEvent, ViewProps } from "react-native";
import { requireNativeView } from "expo";
+import { NativeViewResolutionError } from "../../native/nativeViewResolutionError";
+
const NATIVE_TERMINAL_MODULE_NAME = "T3TerminalSurface";
interface ExpoGlobalWithViewConfig {
@@ -33,6 +35,7 @@ export interface NativeTerminalSurfaceProps extends ViewProps {
}
let cachedNativeTerminalSurfaceView: ComponentType<NativeTerminalSurfaceProps> | undefined;
+let nativeTerminalSurfaceViewResolutionFailed = false;
function getExpoViewConfig(moduleName: string) {
return (globalThis as typeof globalThis & ExpoGlobalWithViewConfig).expo?.getViewConfig?.(
@@ -45,6 +48,10 @@ export function resolveNativeTerminalSurfaceView(): ComponentType<NativeTerminal
return cachedNativeTerminalSurfaceView;
}
+ if (nativeTerminalSurfaceViewResolutionFailed) {
+ return null;
+ }
+
if (getExpoViewConfig(NATIVE_TERMINAL_MODULE_NAME) == null) {
return null;
}
@@ -53,7 +60,14 @@ export function resolveNativeTerminalSurfaceView(): ComponentType<NativeTerminal
cachedNativeTerminalSurfaceView = requireNativeView<NativeTerminalSurfaceProps>(
NATIVE_TERMINAL_MODULE_NAME,
);
- } catch {
+ } catch (cause) {
+ nativeTerminalSurfaceViewResolutionFailed = true;
+ console.error(
+ new NativeViewResolutionError({
+ nativeModuleName: NATIVE_TERMINAL_MODULE_NAME,
+ cause,
+ }),
+ );
return null;
}
diff --git a/apps/mobile/src/native/nativeViewResolutionError.ts b/apps/mobile/src/native/nativeViewResolutionError.ts
new file mode 100644
index 000000000..bfcf8351a
--- /dev/null
+++ b/apps/mobile/src/native/nativeViewResolutionError.ts
@@ -0,0 +1,13 @@
+import * as Schema from "effect/Schema";
+
+export class NativeViewResolutionError extends Schema.TaggedErrorClass<NativeViewResolutionError>()(
+ "NativeViewResolutionError",
+ {
+ nativeModuleName: Schema.String,
+ cause: Schema.Defect(),
+ },
+) {
+ override get message(): string {
+ return `Failed to resolve native view ${this.nativeModuleName}.`;
+ }
+}