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
This commit is contained in:
1 parent
7266fafbf6
commit
c1caaa3520
2 files changed
+20
-5
No files matched your search
@@ -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<string>) =>
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user