Skip to content

Commit da68b1c

Browse files
saphidclaude
andcommitted
fix(server): keep Codex error text in cause, not the failure detail
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e026556 commit da68b1c

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

‎apps/server/src/textGeneration/CodexTextGeneration.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
310310
),
311311
);
312312

313-
it.effect("reports Codex's final error instead of its banner and echoed prompt", () =>
313+
it.effect("keeps Codex's banner, prompt, and error text out of the failure detail", () =>
314314
withFakeCodexEnv(
315315
{
316316
output: "",
@@ -333,8 +333,10 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
333333
modelSelection: DEFAULT_TEST_MODEL_SELECTION,
334334
})
335335
.pipe(Effect.flip);
336-
expect(error.detail).toBe(
337-
"Codex CLI command failed: unexpected status 401 Unauthorized: Missing bearer authentication",
336+
expect(error.detail).toBe("Codex CLI command failed with code 1.");
337+
expect(error.detail).not.toContain("Unauthorized");
338+
expect(error.cause).toEqual(
339+
new Error("unexpected status 401 Unauthorized: Missing bearer authentication"),
338340
);
339341
}),
340342
),

‎apps/server/src/textGeneration/CodexTextGeneration.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,14 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(func
337337
// Codex echoes its banner and the whole prompt to stderr before reporting the error.
338338
const stderrLines = stderr.trim().split("\n");
339339
const lastErrorLine = stderrLines.findLastIndex((line) => line.startsWith("ERROR: "));
340-
const stderrDetail =
340+
const output =
341341
lastErrorLine === -1
342-
? stderr.trim()
342+
? stderr.trim() || stdout.trim()
343343
: stderrLines.slice(lastErrorLine).join("\n").slice("ERROR: ".length);
344-
const stdoutDetail = stdout.trim();
345-
const detail = stderrDetail.length > 0 ? stderrDetail : stdoutDetail;
346344
return yield* new TextGenerationError({
347345
operation,
348-
detail:
349-
detail.length > 0
350-
? `Codex CLI command failed: ${detail}`
351-
: `Codex CLI command failed with code ${exitCode}.`,
346+
detail: `Codex CLI command failed with code ${exitCode}.`,
347+
...(output.length > 0 ? { cause: new Error(output) } : {}),
352348
});
353349
}
354350
});

0 commit comments

Comments
 (0)