mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
fix: remove double error reporting in parseAndSetStructuredOutputs
Fixed error handling anti-pattern identified in PR review where the function was calling core.setFailed() AND throwing errors, causing confusion about error handling flow. Changes: - parseAndSetStructuredOutputs now just throws errors without calling core.setFailed() - follows single responsibility principle - Caller (runClaude) catches errors and calls core.setFailed() once - Removed unnecessary structuredOutputSuccess boolean flag - Clearer error handling flow: function parses/throws, caller decides how to handle failures Addresses review comment: https://github.com/anthropics/claude-code-action/pull/683#discussion_r2539741001 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -159,14 +159,9 @@ async function parseAndSetStructuredOutputs(
|
|||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
core.setFailed(error.message);
|
|
||||||
throw error; // Preserve original error and stack trace
|
throw error; // Preserve original error and stack trace
|
||||||
}
|
}
|
||||||
const wrappedError = new Error(
|
throw new Error(`Failed to parse structured outputs: ${error}`);
|
||||||
`Failed to parse structured outputs: ${error}`,
|
|
||||||
);
|
|
||||||
core.setFailed(wrappedError.message);
|
|
||||||
throw wrappedError;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,24 +354,20 @@ export async function runClaude(promptPath: string, options: ClaudeOptions) {
|
|||||||
core.setOutput("execution_file", EXECUTION_FILE);
|
core.setOutput("execution_file", EXECUTION_FILE);
|
||||||
|
|
||||||
// Parse and set structured outputs only if user provided json_schema
|
// Parse and set structured outputs only if user provided json_schema
|
||||||
let structuredOutputSuccess = true;
|
|
||||||
if (process.env.JSON_SCHEMA) {
|
if (process.env.JSON_SCHEMA) {
|
||||||
try {
|
try {
|
||||||
await parseAndSetStructuredOutputs(EXECUTION_FILE);
|
await parseAndSetStructuredOutputs(EXECUTION_FILE);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
structuredOutputSuccess = false;
|
const errorMessage =
|
||||||
// Error already logged by parseAndSetStructuredOutputs
|
error instanceof Error ? error.message : String(error);
|
||||||
|
core.setFailed(errorMessage);
|
||||||
|
core.setOutput("conclusion", "failure");
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set conclusion after structured output parsing (which may fail)
|
// Set conclusion to success if we reached here
|
||||||
core.setOutput(
|
core.setOutput("conclusion", "success");
|
||||||
"conclusion",
|
|
||||||
structuredOutputSuccess ? "success" : "failure",
|
|
||||||
);
|
|
||||||
if (!structuredOutputSuccess) {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
core.setOutput("conclusion", "failure");
|
core.setOutput("conclusion", "failure");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user