From f551cdf070b0d99ab76c15fb9a4115a352d77889 Mon Sep 17 00:00:00 2001 From: inigo Date: Tue, 18 Nov 2025 14:13:57 -0800 Subject: [PATCH] fix: remove double error reporting in parseAndSetStructuredOutputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- base-action/src/run-claude.ts | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/base-action/src/run-claude.ts b/base-action/src/run-claude.ts index 7c0a8ff..058ad8f 100644 --- a/base-action/src/run-claude.ts +++ b/base-action/src/run-claude.ts @@ -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");