@devries-cameron20 / t3code Mirror · read-only / commits / bd8e3ee008
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 24, 22:45 UTC

Align text generation error catches (#3292)

Co-authored-by: codex <codex@users.noreply.github.com>

Julius Marminge committed Jun 20, 2026 at 12:29 UTC bd8e3ee008e4c78085ebfbf47bf216389a92ac75
5 files changed +91 -114
apps/server/src/textGeneration/ClaudeTextGeneration.ts
+20 -18
@@ -234,28 +234,30 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
234 );
235
236 const envelope = yield* decodeClaudeOutputEnvelope(rawStdout).pipe(
237 - Effect.catchTag("SchemaError", (cause) =>
238 - Effect.fail(
239 - new TextGenerationError({
240 - operation,
241 - detail: "Claude CLI returned unexpected output format.",
242 - cause,
243 - }),
244 - ),
245 - ),
237 + Effect.catchTags({
238 + SchemaError: (cause) =>
239 + Effect.fail(
240 + new TextGenerationError({
241 + operation,
242 + detail: "Claude CLI returned unexpected output format.",
243 + cause,
244 + }),
245 + ),
246 + }),
247 );
248
249 const decodeOutput = Schema.decodeEffect(outputSchemaJson);
250 return yield* decodeOutput(envelope.structured_output).pipe(
250 - Effect.catchTag("SchemaError", (cause) =>
251 - Effect.fail(
252 - new TextGenerationError({
253 - operation,
254 - detail: "Claude returned invalid structured output.",
255 - cause,
256 - }),
257 - ),
258 - ),
251 + Effect.catchTags({
252 + SchemaError: (cause) =>
253 + Effect.fail(
254 + new TextGenerationError({
255 + operation,
256 + detail: "Claude returned invalid structured output.",
257 + cause,
258 + }),
259 + ),
260 + }),
261 );
262 });
263
apps/server/src/textGeneration/CodexTextGeneration.ts
+10 -9
@@ -281,15 +281,16 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(func
281 }),
282 ),
283 Effect.flatMap(decodeOutput),
284 - Effect.catchTag("SchemaError", (cause) =>
285 - Effect.fail(
286 - new TextGenerationError({
287 - operation,
288 - detail: "Codex returned invalid structured output.",
289 - cause,
290 - }),
291 - ),
292 - ),
284 + Effect.catchTags({
285 + SchemaError: (cause) =>
286 + Effect.fail(
287 + new TextGenerationError({
288 + operation,
289 + detail: "Codex returned invalid structured output.",
290 + cause,
291 + }),
292 + ),
293 + }),
294 );
295 }).pipe(Effect.ensuring(cleanup));
296 });
apps/server/src/textGeneration/CursorTextGeneration.ts
+27 -40
@@ -28,30 +28,7 @@ import {
28
29 const CURSOR_TIMEOUT_MS = 180_000;
30
31 -function mapCursorAcpError(
32 - operation:
33 - | "generateCommitMessage"
34 - | "generatePrContent"
35 - | "generateBranchName"
36 - | "generateThreadTitle",
37 - detail: string,
38 - cause: unknown,
39 -): TextGenerationError {
40 - return new TextGenerationError({
41 - operation,
42 - detail,
43 - ...(cause !== undefined ? { cause } : {}),
44 - });
45 -}
46 -
47 -function isTextGenerationError(error: unknown): error is TextGenerationError {
48 - return (
49 - typeof error === "object" &&
50 - error !== null &&
51 - "_tag" in error &&
52 - error._tag === "TextGenerationError"
53 - );
54 -}
31 +const isTextGenerationError = Schema.is(TextGenerationError);
32
33 /**
34 * Build a Cursor text-generation closure bound to a specific `CursorSettings`
@@ -111,13 +88,14 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fu
88 model: modelSelection.model,
89 selections: modelSelection.options,
90 mapError: ({ cause, configId, step }) =>
114 - mapCursorAcpError(
91 + new TextGenerationError({
92 operation,
116 - step === "set-config-option"
117 - ? `Failed to set Cursor ACP config option "${configId}" for text generation.`
118 - : "Failed to set Cursor ACP base model for text generation.",
93 + detail:
94 + step === "set-config-option"
95 + ? `Failed to set Cursor ACP config option "${configId}" for text generation.`
96 + : "Failed to set Cursor ACP base model for text generation.",
97 cause,
120 - ),
98 + }),
99 });
100
101 return yield* runtime.prompt({
@@ -140,7 +118,11 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fu
118 Effect.mapError((cause) =>
119 isTextGenerationError(cause)
120 ? cause
143 - : mapCursorAcpError(operation, "Cursor ACP request failed.", cause),
121 + : new TextGenerationError({
122 + operation,
123 + detail: "Cursor ACP request failed.",
124 + cause,
125 + }),
126 ),
127 );
128
@@ -157,21 +139,26 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fu
139
140 const decodeOutput = Schema.decodeEffect(Schema.fromJsonString(outputSchemaJson));
141 return yield* decodeOutput(extractJsonObject(rawResult)).pipe(
160 - Effect.catchTag("SchemaError", (cause) =>
161 - Effect.fail(
162 - new TextGenerationError({
163 - operation,
164 - detail: "Cursor Agent returned invalid structured output.",
165 - cause,
166 - }),
167 - ),
168 - ),
142 + Effect.catchTags({
143 + SchemaError: (cause) =>
144 + Effect.fail(
145 + new TextGenerationError({
146 + operation,
147 + detail: "Cursor Agent returned invalid structured output.",
148 + cause,
149 + }),
150 + ),
151 + }),
152 );
153 }).pipe(
154 Effect.mapError((cause) =>
155 isTextGenerationError(cause)
156 ? cause
174 - : mapCursorAcpError(operation, "Cursor ACP text generation failed.", cause),
157 + : new TextGenerationError({
158 + operation,
159 + detail: "Cursor ACP text generation failed.",
160 + cause,
161 + }),
162 ),
163 Effect.scoped,
164 );
apps/server/src/textGeneration/GrokTextGeneration.ts
+24 -38
@@ -31,30 +31,7 @@ import {
31
32 const GROK_TIMEOUT_MS = 180_000;
33
34 -function mapGrokAcpError(
35 - operation:
36 - | "generateCommitMessage"
37 - | "generatePrContent"
38 - | "generateBranchName"
39 - | "generateThreadTitle",
40 - detail: string,
41 - cause: unknown,
42 -): TextGenerationError {
43 - return new TextGenerationError({
44 - operation,
45 - detail,
46 - ...(cause !== undefined ? { cause } : {}),
47 - });
48 -}
49 -
50 -function isTextGenerationError(error: unknown): error is TextGenerationError {
51 - return (
52 - typeof error === "object" &&
53 - error !== null &&
54 - "_tag" in error &&
55 - error._tag === "TextGenerationError"
56 - );
57 -}
34 +const isTextGenerationError = Schema.is(TextGenerationError);
35
36 export const makeGrokTextGeneration = Effect.fn("makeGrokTextGeneration")(function* (
37 grokSettings: GrokSettings,
@@ -109,11 +86,11 @@ export const makeGrokTextGeneration = Effect.fn("makeGrokTextGeneration")(functi
86 currentModelId: currentGrokModelIdFromSessionSetup(started.sessionSetupResult),
87 requestedModelId: resolvedModel,
88 mapError: (cause) =>
112 - mapGrokAcpError(
89 + new TextGenerationError({
90 operation,
114 - "Failed to set Grok ACP base model for text generation.",
91 + detail: "Failed to set Grok ACP base model for text generation.",
92 cause,
116 - ),
93 + }),
94 });
95
96 return yield* runtime.prompt({
@@ -133,7 +110,11 @@ export const makeGrokTextGeneration = Effect.fn("makeGrokTextGeneration")(functi
110 Effect.mapError((cause: EffectAcpErrors.AcpError | TextGenerationError) =>
111 isTextGenerationError(cause)
112 ? cause
136 - : mapGrokAcpError(operation, "Grok ACP request failed.", cause),
113 + : new TextGenerationError({
114 + operation,
115 + detail: "Grok ACP request failed.",
116 + cause,
117 + }),
118 ),
119 );
120
@@ -150,21 +131,26 @@ export const makeGrokTextGeneration = Effect.fn("makeGrokTextGeneration")(functi
131
132 const decodeOutput = Schema.decodeEffect(Schema.fromJsonString(outputSchemaJson));
133 return yield* decodeOutput(extractJsonObject(trimmed)).pipe(
153 - Effect.catchTag("SchemaError", (cause) =>
154 - Effect.fail(
155 - new TextGenerationError({
156 - operation,
157 - detail: "Grok Agent returned invalid structured output.",
158 - cause,
159 - }),
160 - ),
161 - ),
134 + Effect.catchTags({
135 + SchemaError: (cause) =>
136 + Effect.fail(
137 + new TextGenerationError({
138 + operation,
139 + detail: "Grok Agent returned invalid structured output.",
140 + cause,
141 + }),
142 + ),
143 + }),
144 );
145 }).pipe(
146 Effect.mapError((cause) =>
147 isTextGenerationError(cause)
148 ? cause
167 - : mapGrokAcpError(operation, "Grok ACP text generation failed.", cause),
149 + : new TextGenerationError({
150 + operation,
151 + detail: "Grok ACP text generation failed.",
152 + cause,
153 + }),
154 ),
155 Effect.scoped,
156 );
apps/server/src/textGeneration/OpenCodeTextGeneration.ts
+10 -9
@@ -348,15 +348,16 @@ export const makeOpenCodeTextGeneration = Effect.fn("makeOpenCodeTextGeneration"
348
349 const decodeOutput = Schema.decodeEffect(Schema.fromJsonString(input.outputSchemaJson));
350 return yield* decodeOutput(extractJsonObject(rawOutput)).pipe(
351 - Effect.catchTag("SchemaError", (cause) =>
352 - Effect.fail(
353 - new TextGenerationError({
354 - operation: input.operation,
355 - detail: "OpenCode returned invalid structured output.",
356 - cause,
357 - }),
358 - ),
359 - ),
351 + Effect.catchTags({
352 + SchemaError: (cause) =>
353 + Effect.fail(
354 + new TextGenerationError({
355 + operation: input.operation,
356 + detail: "OpenCode returned invalid structured output.",
357 + cause,
358 + }),
359 + ),
360 + }),
361 );
362 });
363