Align text generation error catches (#3292)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
c1d8a22f07
commit
bd8e3ee008
5 files changed
+91
-114
No files matched your search
@@ -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,
|
||||
}),
|
||||
),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
|
||||
@@ -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")(fu
|
||||
model: 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")(fu
|
||||
Effect.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")(fu
|
||||
|
||||
const 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,
|
||||
);
|
||||
|
||||
@@ -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")(functi
|
||||
currentModelId: 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")(functi
|
||||
Effect.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")(functi
|
||||
|
||||
const 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,
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user