Skip to content

Conversation

@LearningCircuit
Copy link
Owner

Summary

  • Fixes workflow error handling to display actual error messages from ai-reviewer.sh
  • Previously, failures would show only "Error: Process completed with exit code 1" without details
  • Now captures and displays the full error output for easier debugging

Changes

  • Temporarily disable shell errexit before running ai-reviewer.sh
  • Capture both stdout and stderr with proper redirection
  • Store and check exit code separately
  • Display full error output when script fails
  • Include exit code in debug mode output

Test plan

  • The next AI review run will properly display any error messages if failures occur
  • This PR itself will test the error handling when the AI review is triggered

Related

Previously, when ai-reviewer.sh failed with exit code 1, the workflow
would immediately stop due to shell errexit (-e flag) without displaying
the actual error message. This made debugging failures very difficult.

Changes:
- Temporarily disable errexit with 'set +e' before running ai-reviewer.sh
- Capture both stdout and stderr with '2>&1' redirection
- Store the exit code separately for inspection
- Re-enable errexit with 'set -e' after capture
- Check exit code and display full error output if non-zero
- Include exit code in debug output for better troubleshooting

This fix ensures that when the AI reviewer fails, users will see the
actual error message (e.g., "Missing OPENROUTER_API_KEY", "Diff too large",
"API call failed") instead of just "Error: Process completed with exit code 1".
@LearningCircuit LearningCircuit added the ai_code_review Friendly AI Code Review label Nov 13, 2025
@github-actions
Copy link

AI response could not be processed. Please check the workflow logs for debugging information.

The workflow's stderr capture (2>&1) was picking up progress messages
from ai-reviewer.sh, contaminating the JSON response. Now these messages
only appear in debug mode, keeping stdout clean for JSON parsing.
@LearningCircuit LearningCircuit added ai_code_review Friendly AI Code Review and removed ai_code_review Friendly AI Code Review labels Nov 13, 2025
@github-actions
Copy link

AI Code Review

This PR effectively fixes error handling and debugging output contamination issues in the AI reviewer workflow.

🔒 Security

  • No security concerns identified. The 2>&1 stderr capture is safe here as the script only outputs progress messages (now gated by DEBUG_MODE). No sensitive data exposure risk from the changes.

Code Quality & Best Practices

✅ Strengths:

  • Proper error capture pattern: disabling errexit, capturing exit code, then re-enabling
  • DEBUG_MODE gating prevents stderr contamination of JSON output, fixing the parsing issue mentioned in commit history
  • Clear error messaging with exit code and full output for debugging
  • Graceful degradation when GitHub API calls fail (intentional design)

⚠️ Minor Improvements:

  • Useless use of cat: cat diff.txt | bash ai-reviewer.sh should be bash ai-reviewer.sh < diff.txt for efficiency
  • Overly aggressive error suppression: gh api ... 2>/dev/null || echo "" hides authentication/network issues. Consider logging API failures to stderr when DEBUG_MODE=true
  • DRY principle: The repeated if [ "$DEBUG_MODE" = "true" ] checks could be refactored into a helper function, though this is acceptable for shell scripts

Performance

  • No impact. Changes are purely control-flow and output-related.

Testing Considerations

  • The fix itself will validate the error handling on this PR's AI review run
  • Consider testing the failure path by temporarily introducing a syntax error in ai-reviewer.sh

Review by Friendly AI Reviewer - made with ❤️

@github-actions github-actions bot added bug Something isn't working enhancement New feature or request ci Auto-created by AI reviewer and removed ai_code_review Friendly AI Code Review labels Nov 13, 2025
@LearningCircuit LearningCircuit merged commit 3beb794 into main Nov 13, 2025
1 check passed
@LearningCircuit LearningCircuit deleted the fix/capture-ai-reviewer-errors branch November 13, 2025 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci Auto-created by AI reviewer enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants