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

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex authored and GitHub committed 2026-06-20 11:06:08 -07:00
1 parent 350e229f7a
commit 779c237487
5 files changed
+71 -4

No files matched your search

@@ -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);
});
});
@@ -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;
}
@@ -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);
});
});
@@ -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;
}
@@ -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}.`;
}
}