The best way to control Claude Code, Codex and more from any computer or phone
Normalize Git and PTY adapter errors across services
- Use domain errors directly in GitManager tests (`GitHubCliError`, `TextGenerationError`) - Remove fixture-only GH error normalization in test scaffolding - Introduce shared `PtyAdapterInitializationError` and use it in NodePTY adapter init
Julius Marminge committed
Feb 26, 2026 at 18:05 UTC
a2330938d6f3c2090f4af3dfc964efceca8956a3
2 files changed
+26
-52
apps/server/src/git/Layers/GitManager.test.ts
+17
-41
@@ -3,7 +3,7 @@ import path from "node:path";
3
4
import * as NodeServices from "@effect/platform-node/NodeServices";
5
import { it } from "@effect/vitest";
6
-import { Effect, FileSystem, Layer, PlatformError, Schema, Scope } from "effect";
6
+import { Effect, FileSystem, Layer, PlatformError, Scope } from "effect";
7
import { expect } from "vitest";
8
9
import { GitCommandError, GitHubCliError, TextGenerationError } from "../Errors.ts";
@@ -19,16 +19,11 @@ import { GitService } from "../Services/GitService.ts";
19
import { GitCoreLive } from "./GitCore.ts";
20
import { makeGitManager } from "./GitManager.ts";
21
22
-class GitFixtureError extends Schema.TaggedErrorClass<GitFixtureError>()("GitFixtureError", {
23
- message: Schema.String,
24
- cause: Schema.optional(Schema.Defect),
25
-}) {}
26
-
22
interface FakeGhScenario {
23
prListSequence?: string[];
24
createdPrUrl?: string;
25
defaultBranch?: string;
31
- failWith?: GitFixtureError;
26
+ failWith?: GitHubCliError;
27
}
28
29
interface FakeGitTextGeneration {
@@ -37,7 +32,7 @@ interface FakeGitTextGeneration {
32
branch: string | null;
33
stagedSummary: string;
34
stagedPatch: string;
40
- }) => Effect.Effect<{ subject: string; body: string }, GitFixtureError>;
35
+ }) => Effect.Effect<{ subject: string; body: string }, TextGenerationError>;
36
generatePrContent: (input: {
37
cwd: string;
38
baseBranch: string;
@@ -45,7 +40,7 @@ interface FakeGitTextGeneration {
40
commitSummary: string;
41
diffSummary: string;
42
diffPatch: string;
48
- }) => Effect.Effect<{ title: string; body: string }, GitFixtureError>;
43
+ }) => Effect.Effect<{ title: string; body: string }, TextGenerationError>;
44
}
45
46
function makeTempDir(
@@ -144,34 +139,6 @@ function createTextGeneration(overrides: Partial<FakeGitTextGeneration> = {}): T
139
};
140
}
141
147
-const normalizeGhError = (error: GitFixtureError): GitHubCliError => {
148
- if (error.message.includes("Command not found: gh")) {
149
- return new GitHubCliError({
150
- operation: "execute",
151
- detail: "GitHub CLI (`gh`) is required but not available on PATH.",
152
- cause: error,
153
- });
154
- }
155
- const lower = error.message.toLowerCase();
156
- if (
157
- lower.includes("authentication failed") ||
158
- lower.includes("not logged in") ||
159
- lower.includes("gh auth login") ||
160
- lower.includes("no oauth token")
161
- ) {
162
- return new GitHubCliError({
163
- operation: "execute",
164
- detail: "GitHub CLI is not authenticated. Run `gh auth login` and retry.",
165
- cause: error,
166
- });
167
- }
168
- return new GitHubCliError({
169
- operation: "execute",
170
- detail: error.message,
171
- cause: error,
172
- });
173
-};
174
-
142
function createGitHubCliWithFakeGh(scenario: FakeGhScenario = {}): {
143
service: GitHubCliShape;
144
ghCalls: string[];
@@ -184,7 +151,7 @@ function createGitHubCliWithFakeGh(scenario: FakeGhScenario = {}): {
151
ghCalls.push(args.join(" "));
152
153
if (scenario.failWith) {
187
- return Effect.fail(normalizeGhError(scenario.failWith));
154
+ return Effect.fail(scenario.failWith);
155
}
156
157
if (args[0] === "pr" && args[1] === "list") {
@@ -378,7 +345,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
345
346
const { manager } = yield* makeManager({
347
ghScenario: {
381
- failWith: new GitFixtureError({ message: "Command not found: gh" }),
348
+ failWith: new GitHubCliError({
349
+ operation: "execute",
350
+ detail: "GitHub CLI (`gh`) is required but not available on PATH.",
351
+ }),
352
},
353
});
354
@@ -622,7 +592,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
592
593
const { manager } = yield* makeManager({
594
ghScenario: {
625
- failWith: new GitFixtureError({ message: "Command not found: gh" }),
595
+ failWith: new GitHubCliError({
596
+ operation: "execute",
597
+ detail: "GitHub CLI (`gh`) is required but not available on PATH.",
598
+ }),
599
},
600
});
601
@@ -648,7 +621,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
621
622
const { manager } = yield* makeManager({
623
ghScenario: {
651
- failWith: new GitFixtureError({ message: "authentication failed" }),
624
+ failWith: new GitHubCliError({
625
+ operation: "execute",
626
+ detail: "GitHub CLI is not authenticated. Run `gh auth login` and retry.",
627
+ }),
628
},
629
});
630
apps/server/src/terminal/Layers/NodePTY.ts
+9
-11
@@ -1,18 +1,16 @@
1
import { createRequire } from "node:module";
2
3
-import { Effect, FileSystem, Layer, Path, Schema } from "effect";
4
-import { PtyAdapter, PtyAdapterShape, PtyExitEvent, PtyProcess } from "../Services/PTY";
3
+import { Effect, FileSystem, Layer, Path } from "effect";
4
+import {
5
+ PtyAdapter,
6
+ PtyAdapterInitializationError,
7
+ PtyAdapterShape,
8
+ PtyExitEvent,
9
+ PtyProcess,
10
+} from "../Services/PTY";
11
12
let didEnsureSpawnHelperExecutable = false;
13
8
-export class NodePtyAdapterError extends Schema.TaggedErrorClass<NodePtyAdapterError>()(
9
- "NodePtyAdapterError",
10
- {
11
- message: Schema.String,
12
- cause: Schema.optional(Schema.Defect),
13
- },
14
-) {}
15
-
14
const resolveNodePtySpawnHelperPath = Effect.gen(function* () {
15
const requireForNodePty = createRequire(import.meta.url);
16
const path = yield* Path.Path;
@@ -101,7 +99,7 @@ export const NodePtyAdapterLive = Layer.effect(
99
const nodePty = yield* Effect.tryPromise({
100
try: () => import("node-pty"),
101
catch: (cause) =>
104
- new NodePtyAdapterError({
102
+ new PtyAdapterInitializationError({
103
message: "failed to load node-pty module",
104
cause,
105
}),