From c1caaa35204fbe2cab796a552c8dcc6db0019732 Mon Sep 17 00:00:00 2001 From: Pixel Perfect Date: Wed, 8 Jul 2026 22:55:34 -0700 Subject: [PATCH] Handle init failure surfacing and empty XDG_CONFIG_HOME - Attach a rejection handler to the terminal WASM init so a load failure logs, shows a message in the viewport, and clears on retry instead of leaving a blank pane and an unhandled rejection - Treat an empty XDG_CONFIG_HOME as unset per the XDG spec instead of resolving the Ghostty config relative to the server cwd --- apps/server/src/terminal/ghosttyStyle.ts | 7 ++++++- .../src/components/ThreadTerminalDrawer.tsx | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/server/src/terminal/ghosttyStyle.ts b/apps/server/src/terminal/ghosttyStyle.ts index dc20fe9c30..ed20287410 100644 --- a/apps/server/src/terminal/ghosttyStyle.ts +++ b/apps/server/src/terminal/ghosttyStyle.ts @@ -187,7 +187,12 @@ export const loadGhosttyTerminalStyle: Effect.Effect< const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const home = NodeOS.homedir(); - const xdgConfigHome = process.env["XDG_CONFIG_HOME"] ?? path.join(home, ".config"); + // Per the XDG spec an empty XDG_CONFIG_HOME must be treated as unset. + const xdgConfigHomeEnv = process.env["XDG_CONFIG_HOME"]; + const xdgConfigHome = + xdgConfigHomeEnv !== undefined && xdgConfigHomeEnv.length > 0 + ? xdgConfigHomeEnv + : path.join(home, ".config"); const readFirstExisting = (candidates: ReadonlyArray) => Effect.gen(function* () { diff --git a/apps/web/src/components/ThreadTerminalDrawer.tsx b/apps/web/src/components/ThreadTerminalDrawer.tsx index 6cc8a6ffe8..9ef033ffa6 100644 --- a/apps/web/src/components/ThreadTerminalDrawer.tsx +++ b/apps/web/src/components/ThreadTerminalDrawer.tsx @@ -500,6 +500,8 @@ export function TerminalViewport({ let teardown: (() => void) | undefined; const setUpTerminal = (mount: HTMLDivElement): (() => void) => { + // Clear any failure message left by an earlier init attempt. + mount.textContent = ""; const localApi = readLocalApi(); const style = readTerminalStyle(); @@ -887,10 +889,18 @@ export function TerminalViewport({ }; }; - void ensureGhosttyReady().then(() => { - if (effectDisposed || containerRef.current !== mountElement) return; - teardown = setUpTerminal(mountElement); - }); + void ensureGhosttyReady().then( + () => { + if (effectDisposed || containerRef.current !== mountElement) return; + teardown = setUpTerminal(mountElement); + }, + (error: unknown) => { + if (effectDisposed || containerRef.current !== mountElement) return; + console.error("ghostty-web terminal failed to initialize", error); + mountElement.textContent = + "Terminal failed to initialize. Close and reopen the terminal to retry."; + }, + ); return () => { effectDisposed = true;