Fix failing "sync" job: handle Sentry API 403 gracefully instead of crashing - #276
Conversation
Co-authored-by: LightSage <46062298+LightSage@users.noreply.github.com>
| status = exc.response.status_code if exc.response is not None else None | ||
| if status in (401, 403): | ||
| print( | ||
| f"::warning::Sentry API request failed with HTTP {status}. " |
There was a problem hiding this comment.
Change ::warning:: to use a warning emoji.
There was a problem hiding this comment.
Updated to use a ::warning:: in 1e5f7f0.
| "and/or 'project:read' scopes required to list issues. " | ||
| "Skipping this run without creating GitHub issues." | ||
| ) | ||
| return 0 |
There was a problem hiding this comment.
An exception should still be raised so I'm notified if it's failing a run
There was a problem hiding this comment.
Fixed in 1e5f7f0 — it now logs the diagnostic message and re-raises the exception so the job still fails and you're notified.
Co-authored-by: LightSage <46062298+LightSage@users.noreply.github.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe sync script now recognizes Sentry 401/403 responses as an external token-permission issue and reports them clearly while allowing the job to complete; other HTTP failures still propagate for visibility. Flow diagram for graceful Sentry authorization failuresflowchart TD
A[main] --> B["get_new_sentry_issues()"]
B -->|success| C[Process unresolved issues]
B -->|HTTPError| D{status is 401 or 403}
D -->|yes| E[print warning]
E --> F[Return 0 and complete sync]
D -->|no| G[Re-raise HTTPError and fail job]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path=".github/scripts/sentry_to_github_issues.py" line_range="98-104" />
<code_context>
- issues = get_new_sentry_issues()
+ try:
+ issues = get_new_sentry_issues()
+ except requests.exceptions.HTTPError as exc:
+ status = exc.response.status_code if exc.response is not None else None
+ if status in (401, 403):
+ print(
+ f"⚠️ Sentry API request failed with HTTP {status}. "
+ "This usually means SENTRY_AUTH_TOKEN is missing the 'event:read' "
+ "and/or 'project:read' scopes required to list issues."
+ )
+ raise
+
print(f"Found {len(issues)} unresolved Sentry issue(s) in the last {STATS_PERIOD}.")
</code_context>
<issue_to_address>
**issue (bug_risk):** For HTTP 401 or 403 responses, `main` prints the explanatory message and then reaches the unconditional `raise`, so the `HTTPError` remains unhandled and the sync workflow still exits nonzero instead of returning 0.
**Triggers:** When the Sentry issues endpoint returns HTTP 401 or 403.
**Suggested fix:** Return `0` inside the `if status in (401, 403):` branch, before the unconditional `raise`.
```suggestion
if status in (401, 403):
print(
f"⚠️ Sentry API request failed with HTTP {status}. "
"This usually means SENTRY_AUTH_TOKEN is missing the 'event:read' "
"and/or 'project:read' scopes required to list issues."
)
return 0
raise
```
</issue_to_address>
### Comment 2
<location path=".github/scripts/sentry_to_github_issues.py" line_range="99-103" />
<code_context>
+ except requests.exceptions.HTTPError as exc:
+ status = exc.response.status_code if exc.response is not None else None
+ if status in (401, 403):
+ print(
+ f"⚠️ Sentry API request failed with HTTP {status}. "
+ "This usually means SENTRY_AUTH_TOKEN is missing the 'event:read' "
+ "and/or 'project:read' scopes required to list issues."
+ )
+ raise
+
</code_context>
<issue_to_address>
**issue (bug_risk):** The authentication-error message starts with an emoji rather than the `::warning::` GitHub Actions workflow-command prefix, so GitHub Actions treats it as ordinary log output and does not create a warning annotation.
**Triggers:** When the Sentry issues endpoint returns HTTP 401 or 403 and the re-raise bug is fixed.
**Suggested fix:** Prefix the message with `::warning::`, for example `print(f"::warning::Sentry API request failed ...")`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: .github/scripts/sentry_to_github_issues.py:104, .github/scripts/sentry_to_github_issues.py:103
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if status in (401, 403): | ||
| print( | ||
| f"⚠️ Sentry API request failed with HTTP {status}. " | ||
| "This usually means SENTRY_AUTH_TOKEN is missing the 'event:read' " | ||
| "and/or 'project:read' scopes required to list issues." | ||
| ) | ||
| raise |
There was a problem hiding this comment.
issue (bug_risk): For HTTP 401 or 403 responses, main prints the explanatory message and then reaches the unconditional raise, so the HTTPError remains unhandled and the sync workflow still exits nonzero instead of returning 0.
Triggers: When the Sentry issues endpoint returns HTTP 401 or 403.
Suggested fix: Return 0 inside the if status in (401, 403): branch, before the unconditional raise.
| if status in (401, 403): | |
| print( | |
| f"⚠️ Sentry API request failed with HTTP {status}. " | |
| "This usually means SENTRY_AUTH_TOKEN is missing the 'event:read' " | |
| "and/or 'project:read' scopes required to list issues." | |
| ) | |
| raise | |
| if status in (401, 403): | |
| print( | |
| f"⚠️ Sentry API request failed with HTTP {status}. " | |
| "This usually means SENTRY_AUTH_TOKEN is missing the 'event:read' " | |
| "and/or 'project:read' scopes required to list issues." | |
| ) | |
| return 0 | |
| raise |
Co-authored-by: LightSage <46062298+LightSage@users.noreply.github.com>
The scheduled "sync" workflow (
sentry-to-issues.yml) was hard-failing with an unhandledHTTPErrorwhen Sentry's issues-listing API returned403 Forbidden.Root cause
SENTRY_AUTH_TOKENis valid — the siblingsentry.ymlrelease-publish workflow uses the same secret and succeeds consistently./api/0/projects/{org}/{project}/issues/), which requiresevent:read/project:readscopes beyond what release publishing needs (project:releases).Changes
sentry_to_github_issues.py: wrap the Sentry issues fetch in a try/except; on401/403, emit a::warning::annotation explaining the likely missing scopes and exit0instead of raising.Summary by Sourcery
Bug Fixes: