Skip to content

Commit 7a8bab5

Browse files
[codex] Keep PTY spawn errors structural (#3325)
Co-authored-by: codex <codex@users.noreply.github.com>
1 parent 0675252 commit 7a8bab5

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { assert, describe, it } from "@effect/vitest";
2+
import * as Schema from "effect/Schema";
3+
4+
import * as PtyAdapter from "./PtyAdapter.ts";
5+
6+
const isPtySpawnError = Schema.is(PtyAdapter.PtySpawnError);
7+
8+
describe("PtySpawnError", () => {
9+
it("derives messages from structural context while preserving the full cause chain", () => {
10+
const spawnCause = new Error("spawn /bin/zsh ENOENT");
11+
const adapterError = new PtyAdapter.PtySpawnError({
12+
adapter: "node-pty",
13+
shell: "/bin/zsh",
14+
cause: spawnCause,
15+
});
16+
const managerError = new PtyAdapter.PtySpawnError({
17+
adapter: "terminal-manager",
18+
attemptedShells: ["/bin/zsh -o nopromptsp", "/bin/bash"],
19+
cause: adapterError,
20+
});
21+
22+
assert(isPtySpawnError(managerError));
23+
assert.strictEqual(
24+
managerError.message,
25+
"Failed to spawn PTY process with terminal-manager. Tried shells: /bin/zsh -o nopromptsp, /bin/bash.",
26+
);
27+
assert.strictEqual(
28+
adapterError.message,
29+
"Failed to spawn PTY process '/bin/zsh' with node-pty.",
30+
);
31+
assert.strictEqual(managerError.cause, adapterError);
32+
assert.strictEqual(adapterError.cause, spawnCause);
33+
});
34+
});

apps/server/src/terminal/PtyAdapter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export class PtySpawnError extends Schema.TaggedErrorClass<PtySpawnError>()("Pty
2525
this.attemptedShells === undefined || this.attemptedShells.length === 0
2626
? ""
2727
: ` Tried shells: ${this.attemptedShells.join(", ")}.`;
28-
const causeMessage =
29-
this.cause instanceof Error && this.cause.message.length > 0 ? ` ${this.cause.message}` : "";
30-
return `Failed to spawn PTY process${shell} with ${this.adapter}.${attemptedShells}${causeMessage}`;
28+
return `Failed to spawn PTY process${shell} with ${this.adapter}.${attemptedShells}`;
3129
}
3230
}
3331

0 commit comments

Comments
 (0)