From 7a8bab5d9df80e06782033d1ee252400e6f048b1 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 20 Jun 2026 10:58:03 -0700 Subject: [PATCH] [codex] Keep PTY spawn errors structural (#3325) Co-authored-by: codex --- apps/server/src/terminal/PtyAdapter.test.ts | 34 +++++++++++++++++++++ apps/server/src/terminal/PtyAdapter.ts | 4 +-- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 apps/server/src/terminal/PtyAdapter.test.ts diff --git a/apps/server/src/terminal/PtyAdapter.test.ts b/apps/server/src/terminal/PtyAdapter.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..f4ac9516537d1b91e6e551db8ef53358284949e7 --- /dev/null +++ b/apps/server/src/terminal/PtyAdapter.test.ts @@ -0,0 +1,34 @@ +import { assert, describe, it } from "@effect/vitest"; +import * as Schema from "effect/Schema"; + +import * as PtyAdapter from "./PtyAdapter.ts"; + +const isPtySpawnError = Schema.is(PtyAdapter.PtySpawnError); + +describe("PtySpawnError", () => { + it("derives messages from structural context while preserving the full cause chain", () => { + const spawnCause = new Error("spawn /bin/zsh ENOENT"); + const adapterError = new PtyAdapter.PtySpawnError({ + adapter: "node-pty", + shell: "/bin/zsh", + cause: spawnCause, + }); + const managerError = new PtyAdapter.PtySpawnError({ + adapter: "terminal-manager", + attemptedShells: ["/bin/zsh -o nopromptsp", "/bin/bash"], + cause: adapterError, + }); + + assert(isPtySpawnError(managerError)); + assert.strictEqual( + managerError.message, + "Failed to spawn PTY process with terminal-manager. Tried shells: /bin/zsh -o nopromptsp, /bin/bash.", + ); + assert.strictEqual( + adapterError.message, + "Failed to spawn PTY process '/bin/zsh' with node-pty.", + ); + assert.strictEqual(managerError.cause, adapterError); + assert.strictEqual(adapterError.cause, spawnCause); + }); +}); diff --git a/apps/server/src/terminal/PtyAdapter.ts b/apps/server/src/terminal/PtyAdapter.ts index dafb6f12f4fe2f8d76fcdd7c5b8ad267b0234f58..67147035bb5dfb1ec0ad1e4440c3c19d3fe0a756 100644 --- a/apps/server/src/terminal/PtyAdapter.ts +++ b/apps/server/src/terminal/PtyAdapter.ts @@ -25,9 +25,7 @@ export class PtySpawnError extends Schema.TaggedErrorClass()("Pty this.attemptedShells === undefined || this.attemptedShells.length === 0 ? "" : ` Tried shells: ${this.attemptedShells.join(", ")}.`; - const causeMessage = - this.cause instanceof Error && this.cause.message.length > 0 ? ` ${this.cause.message}` : ""; - return `Failed to spawn PTY process${shell} with ${this.adapter}.${attemptedShells}${causeMessage}`; + return `Failed to spawn PTY process${shell} with ${this.adapter}.${attemptedShells}`; } } -- 2.54.0