Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Align text generation error catches (#3292)
Julius Marmingebd8e3ee008e4
diff --git a/apps/server/src/textGeneration/ClaudeTextGeneration.ts b/apps/server/src/textGeneration/ClaudeTextGeneration.tsindex 872bf936c..453bb62b7 100644--- a/apps/server/src/textGeneration/ClaudeTextGeneration.ts+++ b/apps/server/src/textGeneration/ClaudeTextGeneration.ts@@ -234,28 +234,30 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu);const envelope = yield* decodeClaudeOutputEnvelope(rawStdout).pipe(- Effect.catchTag("SchemaError", (cause) =>- Effect.fail(- new TextGenerationError({- operation,- detail: "Claude CLI returned unexpected output format.",- cause,- }),- ),- ),+ Effect.catchTags({+ SchemaError: (cause) =>+ Effect.fail(+ new TextGenerationError({+ operation,+ detail: "Claude CLI returned unexpected output format.",+ cause,+ }),+ ),+ }),);const decodeOutput = Schema.decodeEffect(outputSchemaJson);return yield* decodeOutput(envelope.structured_output).pipe(- Effect.catchTag("SchemaError", (cause) =>- Effect.fail(- new TextGenerationError({- operation,- detail: "Claude returned invalid structured output.",- cause,- }),- ),- ),+ Effect.catchTags({+ SchemaError: (cause) =>+ Effect.fail(+ new TextGenerationError({+ operation,+ detail: "Claude returned invalid structured output.",+ cause,+ }),+ ),+ }),);});diff --git a/apps/server/src/textGeneration/CodexTextGeneration.ts b/apps/server/src/textGeneration/CodexTextGeneration.tsindex 95783b06c..0e68994fd 100644--- a/apps/server/src/textGeneration/CodexTextGeneration.ts+++ b/apps/server/src/textGeneration/CodexTextGeneration.ts@@ -281,15 +281,16 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(func}),),Effect.flatMap(decodeOutput),- Effect.catchTag("SchemaError", (cause) =>- Effect.fail(- new TextGenerationError({- operation,- detail: "Codex returned invalid structured output.",- cause,- }),- ),- ),+ Effect.catchTags({+ SchemaError: (cause) =>+ Effect.fail(+ new TextGenerationError({+ operation,+ detail: "Codex returned invalid structured output.",+ cause,+ }),+ ),+ }),);}).pipe(Effect.ensuring(cleanup));});diff --git a/apps/server/src/textGeneration/CursorTextGeneration.ts b/apps/server/src/textGeneration/CursorTextGeneration.tsindex 24676789b..3e1f4eb8b 100644--- a/apps/server/src/textGeneration/CursorTextGeneration.ts+++ b/apps/server/src/textGeneration/CursorTextGeneration.ts@@ -28,30 +28,7 @@ import {const CURSOR_TIMEOUT_MS = 180_000;-function mapCursorAcpError(- operation:- | "generateCommitMessage"- | "generatePrContent"- | "generateBranchName"- | "generateThreadTitle",- detail: string,- cause: unknown,-): TextGenerationError {- return new TextGenerationError({- operation,- detail,- ...(cause !== undefined ? { cause } : {}),- });-}--function isTextGenerationError(error: unknown): error is TextGenerationError {- return (- typeof error === "object" &&- error !== null &&- "_tag" in error &&- error._tag === "TextGenerationError"- );-}+const isTextGenerationError = Schema.is(TextGenerationError);/*** Build a Cursor text-generation closure bound to a specific `CursorSettings`@@ -111,13 +88,14 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fumodel: modelSelection.model,selections: modelSelection.options,mapError: ({ cause, configId, step }) =>- mapCursorAcpError(+ new TextGenerationError({operation,- step === "set-config-option"- ? `Failed to set Cursor ACP config option "${configId}" for text generation.`- : "Failed to set Cursor ACP base model for text generation.",+ detail:+ step === "set-config-option"+ ? `Failed to set Cursor ACP config option "${configId}" for text generation.`+ : "Failed to set Cursor ACP base model for text generation.",cause,- ),+ }),});return yield* runtime.prompt({@@ -140,7 +118,11 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fuEffect.mapError((cause) =>isTextGenerationError(cause)? cause- : mapCursorAcpError(operation, "Cursor ACP request failed.", cause),+ : new TextGenerationError({+ operation,+ detail: "Cursor ACP request failed.",+ cause,+ }),),);@@ -157,21 +139,26 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fuconst decodeOutput = Schema.decodeEffect(Schema.fromJsonString(outputSchemaJson));return yield* decodeOutput(extractJsonObject(rawResult)).pipe(- Effect.catchTag("SchemaError", (cause) =>- Effect.fail(- new TextGenerationError({- operation,- detail: "Cursor Agent returned invalid structured output.",- cause,- }),- ),- ),+ Effect.catchTags({+ SchemaError: (cause) =>+ Effect.fail(+ new TextGenerationError({+ operation,+ detail: "Cursor Agent returned invalid structured output.",+ cause,+ }),+ ),+ }),);}).pipe(Effect.mapError((cause) =>isTextGenerationError(cause)? cause- : mapCursorAcpError(operation, "Cursor ACP text generation failed.", cause),+ : new TextGenerationError({+ operation,+ detail: "Cursor ACP text generation failed.",+ cause,+ }),),Effect.scoped,);diff --git a/apps/server/src/textGeneration/GrokTextGeneration.ts b/apps/server/src/textGeneration/GrokTextGeneration.tsindex ab52efb11..1bb582163 100644--- a/apps/server/src/textGeneration/GrokTextGeneration.ts+++ b/apps/server/src/textGeneration/GrokTextGeneration.ts@@ -31,30 +31,7 @@ import {const GROK_TIMEOUT_MS = 180_000;-function mapGrokAcpError(- operation:- | "generateCommitMessage"- | "generatePrContent"- | "generateBranchName"- | "generateThreadTitle",- detail: string,- cause: unknown,-): TextGenerationError {- return new TextGenerationError({- operation,- detail,- ...(cause !== undefined ? { cause } : {}),- });-}--function isTextGenerationError(error: unknown): error is TextGenerationError {- return (- typeof error === "object" &&- error !== null &&- "_tag" in error &&- error._tag === "TextGenerationError"- );-}+const isTextGenerationError = Schema.is(TextGenerationError);export const makeGrokTextGeneration = Effect.fn("makeGrokTextGeneration")(function* (grokSettings: GrokSettings,@@ -109,11 +86,11 @@ export const makeGrokTextGeneration = Effect.fn("makeGrokTextGeneration")(functicurrentModelId: currentGrokModelIdFromSessionSetup(started.sessionSetupResult),requestedModelId: resolvedModel,mapError: (cause) =>- mapGrokAcpError(+ new TextGenerationError({operation,- "Failed to set Grok ACP base model for text generation.",+ detail: "Failed to set Grok ACP base model for text generation.",cause,- ),+ }),});return yield* runtime.prompt({@@ -133,7 +110,11 @@ export const makeGrokTextGeneration = Effect.fn("makeGrokTextGeneration")(functiEffect.mapError((cause: EffectAcpErrors.AcpError | TextGenerationError) =>isTextGenerationError(cause)? cause- : mapGrokAcpError(operation, "Grok ACP request failed.", cause),+ : new TextGenerationError({+ operation,+ detail: "Grok ACP request failed.",+ cause,+ }),),);@@ -150,21 +131,26 @@ export const makeGrokTextGeneration = Effect.fn("makeGrokTextGeneration")(functiconst decodeOutput = Schema.decodeEffect(Schema.fromJsonString(outputSchemaJson));return yield* decodeOutput(extractJsonObject(trimmed)).pipe(- Effect.catchTag("SchemaError", (cause) =>- Effect.fail(- new TextGenerationError({- operation,- detail: "Grok Agent returned invalid structured output.",- cause,- }),- ),- ),+ Effect.catchTags({+ SchemaError: (cause) =>+ Effect.fail(+ new TextGenerationError({+ operation,+ detail: "Grok Agent returned invalid structured output.",+ cause,+ }),+ ),+ }),);}).pipe(Effect.mapError((cause) =>isTextGenerationError(cause)? cause- : mapGrokAcpError(operation, "Grok ACP text generation failed.", cause),+ : new TextGenerationError({+ operation,+ detail: "Grok ACP text generation failed.",+ cause,+ }),),Effect.scoped,);diff --git a/apps/server/src/textGeneration/OpenCodeTextGeneration.ts b/apps/server/src/textGeneration/OpenCodeTextGeneration.tsindex 0ba7726d6..f59e76942 100644--- a/apps/server/src/textGeneration/OpenCodeTextGeneration.ts+++ b/apps/server/src/textGeneration/OpenCodeTextGeneration.ts@@ -348,15 +348,16 @@ export const makeOpenCodeTextGeneration = Effect.fn("makeOpenCodeTextGeneration"const decodeOutput = Schema.decodeEffect(Schema.fromJsonString(input.outputSchemaJson));return yield* decodeOutput(extractJsonObject(rawOutput)).pipe(- Effect.catchTag("SchemaError", (cause) =>- Effect.fail(- new TextGenerationError({- operation: input.operation,- detail: "OpenCode returned invalid structured output.",- cause,- }),- ),- ),+ Effect.catchTags({+ SchemaError: (cause) =>+ Effect.fail(+ new TextGenerationError({+ operation: input.operation,+ detail: "OpenCode returned invalid structured output.",+ cause,+ }),+ ),+ }),);});