From baa1ecb26543eb435fb0fae0e5298c641353a38e Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Wed, 28 May 2025 17:50:45 -0700 Subject: [PATCH] refactor: simplify error capture to show clean error messages only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove complex shell script that captured full output logs - Use core.setOutput in prepare.ts to pass clean error message directly - Avoid exposing potentially sensitive information from logs - Show only the actual error message (e.g. 'Failed to fetch issue data') This provides cleaner, more readable error messages without the risk of exposing sensitive information from debug logs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- action.yml | 21 +-------------------- src/entrypoints/prepare.ts | 5 ++++- test/comment-logic.test.ts | 5 ++--- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/action.yml b/action.yml index 3d60761..ac490ea 100644 --- a/action.yml +++ b/action.yml @@ -81,26 +81,7 @@ runs: id: prepare shell: bash run: | - set +e - # Create a temporary file to capture both stdout and stderr - TEMP_OUTPUT=$(mktemp) - bun run ${{ github.action_path }}/src/entrypoints/prepare.ts 2>&1 | tee "$TEMP_OUTPUT" - PREPARE_EXIT_CODE=${PIPESTATUS[0]} - - # If the command failed, save the error output - if [ $PREPARE_EXIT_CODE -ne 0 ]; then - # Extract last 50 lines of output as error details - ERROR_DETAILS=$(tail -n 50 "$TEMP_OUTPUT") - echo "prepare_error<> $GITHUB_OUTPUT - echo "$ERROR_DETAILS" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - fi - - # Clean up temp file - rm -f "$TEMP_OUTPUT" - - # Exit with the original exit code - exit $PREPARE_EXIT_CODE + bun run ${{ github.action_path }}/src/entrypoints/prepare.ts env: TRIGGER_PHRASE: ${{ inputs.trigger_phrase }} ASSIGNEE_TRIGGER: ${{ inputs.assignee_trigger }} diff --git a/src/entrypoints/prepare.ts b/src/entrypoints/prepare.ts index 1cce680..1470798 100644 --- a/src/entrypoints/prepare.ts +++ b/src/entrypoints/prepare.ts @@ -92,7 +92,10 @@ async function run() { ); core.setOutput("mcp_config", mcpConfig); } catch (error) { - core.setFailed(`Prepare step failed with error: ${error}`); + const errorMessage = error instanceof Error ? error.message : String(error); + core.setFailed(`Prepare step failed with error: ${errorMessage}`); + // Also output the clean error message for the action to capture + core.setOutput("prepare_error", errorMessage); process.exit(1); } } diff --git a/test/comment-logic.test.ts b/test/comment-logic.test.ts index 43f1d4b..7488400 100644 --- a/test/comment-logic.test.ts +++ b/test/comment-logic.test.ts @@ -45,8 +45,7 @@ describe("updateCommentBody", () => { currentBody: "Claude Code is working...", actionFailed: true, executionDetails: { duration_ms: 45000 }, - errorDetails: - "fatal: not a git repository (or any of the parent directories): .git", + errorDetails: "Failed to fetch issue data", }; const result = updateCommentBody(input); @@ -54,7 +53,7 @@ describe("updateCommentBody", () => { expect(result).toContain("[View job]"); expect(result).toContain("
"); expect(result).toContain("Error details"); - expect(result).toContain("fatal: not a git repository"); + expect(result).toContain("Failed to fetch issue data"); // Ensure error details come after the header/links const errorIndex = result.indexOf("
"); const headerIndex = result.indexOf("**Claude encountered an error");