Standardized error responses for all failure scenarios. Always transparent, always provide next steps.
Handle failures gracefully:
Include this file when handling errors:
Use lib/error-handler to handle [error type] gracefully
When: Issue missing trigger label, closed, or not found
Template: ```markdown ā ļø Cannot Process Issue
This issue needs the `claude:auto-fix` label to be processed automatically.
To enable automatic handling:
```bash
gh issue edit
Then run: `/handle-issue
Post to: Issue comment Exit: Gracefully (not a failure)
When: Targeted search and deep analysis return no results
Template: ```markdown š Analysis Incomplete
I searched the codebase but couldn't confidently locate code related to this issue.
What I searched for:
Possible reasons:
Next steps:
Alternatively, this may require manual investigation. ```
Post to: Issue comment Exit: Gracefully (partial success)
When: Can't access GitHub API, can't parse comments
Template: ```markdown ā ļø Approval Check Failed
I couldn't verify approval due to an error:
```
Manual verification:
If the error persists, you can implement the plan manually using the details above. ```
Post to: Issue comment Exit: Error (but actionable)
When: Branch exists, directory conflicts, git errors
Template: ```markdown ā ļø Worktree Setup Failed
Couldn't create isolated workspace:
```
Common fixes: ```bash
git worktree remove .worktrees/fix-issue-
/continue-issue
Manual alternative:
```bash
git checkout -b fix/issue-
``` ```
Post to: Issue comment Exit: Error (but recoverable)
When: Tests fail, compilation errors, execution issues
Strategy: Commit partial progress, create draft PR
Step 1: Post issue comment: ```markdown ā ļø Implementation Completed with Issues
PR created: #
The automated fix encountered some problems but progress has been committed. Please review the draft PR and complete remaining work.
What worked:
What needs attention:
Step 2: Create draft PR:
```bash
gh pr create
--title "[WIP] Fix:
--body "$(cat <<'EOF'
Fixes #
Status: Implementation partially completed but encountered errors.
This PR contains the attempted fix but requires manual review:
Automated implementation encountered issues. Manual review required.
EOF
)"
--label "automated-fix,needs-work"
--draft
```
Exit: Partial success (work preserved)
When: GitHub API errors, permission issues
Template: ```markdown ā Implementation Complete
The fix has been implemented in branch: `fix/issue-
However, PR creation failed:
```
Create PR manually:
```bash
gh pr create --head fix/issue-
Or visit: https://github.com/
Changes made:
All changes have been committed and pushed. ```
Post to: Issue comment Exit: Partial success (code ready, manual PR needed)
function post_error() {
local issue_number=$1
local error_template=$2
local error_message=$3
# Replace placeholders
local formatted_message="${error_template//<error message>/$error_message}"
formatted_message="${formatted_message//<issue-number>/$issue_number}"
# Post to GitHub
gh issue comment "$issue_number" --body "$formatted_message"
# Log locally for debugging
echo "[ERROR] Issue #$issue_number: $error_message" >> ~/.claude/errors.log
}
gh issue view 999 --json title 2>&1
If output contains:
"could not resolve to an Issue" ā Issue not found"HTTP 401" ā Authentication failed"HTTP 403" ā Permission denied"HTTP 404" ā Repository not foundgit worktree add .worktrees/test 2>&1
If output contains:
"already exists" ā Branch or worktree exists"not a git repository" ā Not in git repo"fatal: invalid reference" ā Invalid branch nameWhen spawning agents or executing commands:
For transient GitHub API errors:
function retry_gh_command() {
local max_attempts=3
local attempt=1
local delay=5
while [ $attempt -le $max_attempts ]; do
if $@; then
return 0
fi
echo "Attempt $attempt failed, retrying in ${delay}s..."
sleep $delay
delay=$((delay * 2))
attempt=$((attempt + 1))
done
return 1
}
# Usage
retry_gh_command gh issue view 123 --json title
Always commit work before failing:
# Before any risky operation
git add -A
git commit -m "wip: partial implementation before <operation>" || true
# Try operation
if ! risky_operation; then
# Committed work is preserved
post_error <issue> "implementation_failed" "$error"
fi
If fancy features fail, fall back to basics:
Deep analysis fails ā Use only targeted search
Worktree fails ā Suggest manual branch creation
PR creation fails ā Show manual commands
Fetch issue ā FAIL? ā Error template #1
Parse issue ā (always succeeds)
Search code ā FAIL? ā Error template #2
Generate plan ā (always succeeds)
Post plan ā FAIL? ā Error template #3
Check approval ā FAIL? ā Error template #3
Create worktree ā FAIL? ā Error template #4
Implement fix ā FAIL? ā Error template #5
Create PR ā FAIL? ā Error template #6
All errors logged to help debugging:
# ~/.claude/github-issue-handler.log
[2026-01-16 10:00:00] INFO: handle-issue 42 started
[2026-01-16 10:00:05] ERROR: gh CLI failed: HTTP 401
[2026-01-16 10:00:05] ERROR: Posted error template #3 to issue 42
[2026-01-16 10:00:05] EXIT: Graceful exit with code 1
Not included:
Keep it simple: post to GitHub, log locally, provide next steps.