Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions apps/server/src/terminal/PtyAdapter.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
4 changes: 1 addition & 3 deletions apps/server/src/terminal/PtyAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export class PtySpawnError extends Schema.TaggedErrorClass<PtySpawnError>()("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}`;
}
}

Expand Down
Loading