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) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message);
|
||||
throw error; // Preserve original error and stack trace
|
||||
}
|
||||
const wrappedError = new Error(
|
||||
`Failed to parse structured outputs: ${error}`,
|
||||
);
|
||||
core.setFailed(wrappedError.message);
|
||||
throw wrappedError;
|
||||
throw new Error(`Failed to parse structured outputs: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,24 +354,20 @@ export async function runClaude(promptPath: string, options: ClaudeOptions) {
|
||||
core.setOutput("execution_file", EXECUTION_FILE);
|
||||
|
||||
// Parse and set structured outputs only if user provided json_schema
|
||||
let structuredOutputSuccess = true;
|
||||
if (process.env.JSON_SCHEMA) {
|
||||
try {
|
||||
await parseAndSetStructuredOutputs(EXECUTION_FILE);
|
||||
} catch (error) {
|
||||
structuredOutputSuccess = false;
|
||||
// Error already logged by parseAndSetStructuredOutputs
|
||||
const errorMessage =
|
||||
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)
|
||||
core.setOutput(
|
||||
"conclusion",
|
||||
structuredOutputSuccess ? "success" : "failure",
|
||||
);
|
||||
if (!structuredOutputSuccess) {
|
||||
process.exit(1);
|
||||
}
|
||||
// Set conclusion to success if we reached here
|
||||
core.setOutput("conclusion", "success");
|
||||
} else {
|
||||
core.setOutput("conclusion", "failure");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user