The best way to control Claude Code, Codex and more from any computer or phone
fix(server): HTML preview reports a browser start error instead of an internal error (#22895)
Co-authored-by: ScottN-PV <snorteman@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 21, 2026 at 14:09 UTC
60dc0a044c1d0e2fe305eeb2b3cb6311f4fd2d8b
2 files changed
+37
-1
apps/server/src/htmlRender/HtmlRender.test.ts
+30
-1
@@ -1,11 +1,12 @@
1
// @effect-diagnostics nodeBuiltinImport:off - plain local servers stand in for LAN services.
2
import * as NodeServices from "@effect/platform-node/NodeServices";
3
-import { describe, expect, it } from "@effect/vitest";
3
+import { assert, describe, expect, it } from "@effect/vitest";
4
import { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
5
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
6
import * as HostProcess from "@t3tools/shared/HostProcess";
7
import * as Deferred from "effect/Deferred";
8
import * as Effect from "effect/Effect";
9
+import * as Exit from "effect/Exit";
10
import * as Base64 from "effect/encoding/Base64";
11
import * as Fiber from "effect/Fiber";
12
import * as FileSystem from "effect/FileSystem";
@@ -19,6 +20,7 @@ import * as NodeURL from "node:url";
20
import { resolveAttachmentPathById } from "../attachmentStore.ts";
21
import * as ServerConfig from "../config.ts";
22
import * as HtmlRender from "./HtmlRender.ts";
23
+import { HtmlRenderBrowserError } from "./headlessChrome.ts";
24
import * as PreviewBrowser from "../preview/PreviewBrowser.ts";
25
26
const TEST_BROWSER_ENV = "T3CODE_TEST_HEADLESS_SHELL";
@@ -287,6 +289,33 @@ describe("HtmlRender", () => {
289
}),
290
);
291
292
+ // Windows reports ENOENT asynchronously for this path instead of throwing ENOTDIR.
293
+ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
294
+ "when the browser spawn throws synchronously",
295
+ () => {
296
+ it.live("reports a typed preview error", () =>
297
+ Effect.gen(function* () {
298
+ const fileSystem = yield* FileSystem.FileSystem;
299
+ const path = yield* Path.Path;
300
+ const file = yield* fileSystem.makeTempFileScoped({ prefix: "t3-browser-spawn-" });
301
+ const outcome = yield* HtmlRender.HtmlRender.use((htmlRender) =>
302
+ htmlRender.preview({ html: "<p>x</p>" }).pipe(Effect.flip),
303
+ ).pipe(
304
+ Effect.provide(layerHtmlRender(path.join(file, "chrome-headless-shell"))),
305
+ Effect.exit,
306
+ );
307
+ assert(Exit.isSuccess(outcome), "Expected a typed preview error.");
308
+ const error = outcome.value;
309
+ expect(error).toBeInstanceOf(HtmlRenderBrowserError);
310
+ expect(error.message).toBe(
311
+ "Headless Chrome could not render the page: the browser could not be started.",
312
+ );
313
+ expect(error).toMatchObject({ cause: { code: "ENOTDIR" } });
314
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
315
+ );
316
+ },
317
+ );
318
+
319
it.live("keeps every local file but the page itself out of the browser", (ctx) =>
320
Effect.gen(function* () {
321
const executable = (yield* HostProcess.Environment)[TEST_BROWSER_ENV];
apps/server/src/htmlRender/headlessChrome.ts
+7
@@ -229,6 +229,13 @@ const launchBrowser = Effect.fnUntraced(function* (input: {
229
(cause) =>
230
new HtmlRenderBrowserError({ reason: "the browser could not be started", cause }),
231
),
232
+ // Node throws some spawn errors synchronously, such as `spawn UNKNOWN`
233
+ // when policy blocks the executable; `mapError` cannot catch those.
234
+ Effect.catchDefect((cause) =>
235
+ Effect.fail(
236
+ new HtmlRenderBrowserError({ reason: "the browser could not be started", cause }),
237
+ ),
238
+ ),
239
);
240
241
let stderrTail = "";