GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): report synchronous HTML browser spawn failures · pingdotgg/t3code@cbdd6e8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/htmlRender
    • HtmlRender.test.ts
    • headlessChrome.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/htmlRender/HtmlRender.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/htmlRender/HtmlRender.test.ts
+63-1Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// @effect-diagnostics nodeBuiltinImport:off - plain local servers stand in for LAN services.
22
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";
44
import { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
55
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
66
import * as HostProcess from "@t3tools/shared/HostProcess";
77
import * as Deferred from "effect/Deferred";
88
import * as Effect from "effect/Effect";
9+
import * as Exit from "effect/Exit";
910
import * as Base64 from "effect/encoding/Base64";
1011
import * as Fiber from "effect/Fiber";
1112
import * as FileSystem from "effect/FileSystem";
@@ -19,6 +20,7 @@ import * as NodeURL from "node:url";
1920
import { resolveAttachmentPathById } from "../attachmentStore.ts";
2021
import * as ServerConfig from "../config.ts";
2122
import * as HtmlRender from "./HtmlRender.ts";
23+
import { HtmlRenderBrowserError } from "./headlessChrome.ts";
2224
import * as PreviewBrowser from "../preview/PreviewBrowser.ts";
2325

2426
const TEST_BROWSER_ENV = "T3CODE_TEST_HEADLESS_SHELL";
@@ -287,6 +289,66 @@ describe("HtmlRender", () => {
287289
}),
288290
);
289291

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+
it.live("publishes the page without measured heights", () =>
317+
Effect.gen(function* () {
318+
const fileSystem = yield* FileSystem.FileSystem;
319+
const path = yield* Path.Path;
320+
const file = yield* fileSystem.makeTempFileScoped({ prefix: "t3-browser-spawn-" });
321+
yield* Effect.gen(function* () {
322+
const config = yield* ServerConfig.ServerConfig;
323+
const htmlRender = yield* HtmlRender.HtmlRender;
324+
const outcome = yield* htmlRender
325+
.publish({
326+
threadId: ThreadId.make("thread-html-spawn"),
327+
html: "<p>Browser unavailable</p>",
328+
title: "Saved page",
329+
height: 300,
330+
})
331+
.pipe(Effect.exit);
332+
assert(Exit.isSuccess(outcome), "Expected a published attachment.");
333+
const reference = outcome.value;
334+
expect(reference).toEqual({
335+
attachmentId: expect.any(String),
336+
title: "Saved page",
337+
height: 300,
338+
});
339+
const stored = resolveAttachmentPathById({
340+
attachmentsDir: config.attachmentsDir,
341+
attachmentId: reference.attachmentId,
342+
});
343+
expect(yield* fileSystem.readFileString(stored ?? "")).toContain(
344+
"<p>Browser unavailable</p>",
345+
);
346+
}).pipe(Effect.provide(layerHtmlRender(path.join(file, "chrome-headless-shell"))));
347+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
348+
);
349+
},
350+
);
351+
290352
it.live("keeps every local file but the page itself out of the browser", (ctx) =>
291353
Effect.gen(function* () {
292354
const executable = (yield* HostProcess.Environment)[TEST_BROWSER_ENV];
Collapse file

‎apps/server/src/htmlRender/headlessChrome.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/htmlRender/headlessChrome.ts
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ const launchBrowser = Effect.fnUntraced(function* (input: {
229229
(cause) =>
230230
new HtmlRenderBrowserError({ reason: "the browser could not be started", cause }),
231231
),
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+
),
232239
);
233240

234241
let stderrTail = "";

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.