Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/client/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,21 @@ export async function runCodex(
const codeResult = `\`\`\`\n${result.stdout}\n\`\`\``;

const lastLine = codeResult.split('\n').slice(-2, -1)[0];
const jsonResult = JSON.parse(lastLine);
let jsonResult: unknown;
try {
jsonResult = JSON.parse(lastLine);
} catch (parseError) {
core.error(
`Failed to parse JSON output from Codex: ${
parseError instanceof Error ? parseError.message : String(parseError)
}. Last line: ${lastLine}`
);
throw new Error(
`Failed to parse JSON output from Codex: ${
parseError instanceof Error ? parseError.message : String(parseError)
}`
);
}
let textResult = '';
if (
jsonResult &&
Expand All @@ -120,12 +134,18 @@ export async function runCodex(
// return textResult + "<details><summary>Codex Result</summary>\n\n" + codeResult + "\n</details>";
return textResult;
} catch (error) {
// Log the full error for debugging, check for timeout
// Log the full error for debugging
core.error(
`Error executing Codex command: ${
error instanceof Error ? error.stack : String(error)
}`,
);
if (
error instanceof Error &&
error.message.startsWith('Failed to parse JSON output')
) {
throw error;
}
if (
error instanceof Error &&
'timedOut' in error &&
Expand Down