Skip to content

Fix failing "sync" job: handle Sentry API 403 gracefully instead of crashing - #276

Merged
LightSage merged 4 commits into
masterfrom
copilot/fix-sync-job-failure
Aug 26, 2026
Merged

Fix failing "sync" job: handle Sentry API 403 gracefully instead of crashing#276
LightSage merged 4 commits into
masterfrom
copilot/fix-sync-job-failure

Conversation

Copilot AI commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

The scheduled "sync" workflow (sentry-to-issues.yml) was hard-failing with an unhandled HTTPError when Sentry's issues-listing API returned 403 Forbidden.

Root cause

  • SENTRY_AUTH_TOKEN is valid — the sibling sentry.yml release-publish workflow uses the same secret and succeeds consistently.
  • The 403 is scoped to the issues-listing endpoint (/api/0/projects/{org}/{project}/issues/), which requires event:read/project:read scopes beyond what release publishing needs (project:releases).
  • Token scope is an external configuration concern, not something fixable from repo code.

Changes

  • sentry_to_github_issues.py: wrap the Sentry issues fetch in a try/except; on 401/403, emit a ::warning:: annotation explaining the likely missing scopes and exit 0 instead of raising.
  • All other errors (e.g. 5xx) continue to propagate and fail the job as before, preserving visibility into real bugs.
def main() -> int:
    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"::warning::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. "
                "Skipping this run without creating GitHub issues."
            )
            return 0
        raise
    ...

Summary by Sourcery

Bug Fixes:

  • Handle unauthorized Sentry issues API responses by emitting a warning before the sync job fails.

Co-authored-by: LightSage <46062298+LightSage@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failing GitHub Actions job sync Fix failing "sync" job: handle Sentry API 403 gracefully instead of crashing Aug 26, 2026
Copilot AI requested a review from LightSage August 26, 2026 04:14
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}. "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change ::warning:: to use a warning emoji.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use a ⚠️ emoji instead of ::warning:: in 1e5f7f0.

"and/or 'project:read' scopes required to list issues. "
"Skipping this run without creating GitHub issues."
)
return 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exception should still be raised so I'm notified if it's failing a run

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copilot AI requested a review from LightSage August 26, 2026 13:31

@LightSage LightSage left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@LightSage
LightSage marked this pull request as ready for review August 26, 2026 13:38
@sourcery-ai

sourcery-ai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The 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 failures

flowchart 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]
Loading

File-Level Changes

Change Details Files
Adds targeted handling for Sentry authentication and authorization failures during issue retrieval.
  • Catches HTTP errors around the issues-listing request.
  • Detects 401 and 403 responses and prints a warning identifying likely token-scope requirements.
  • Keeps non-authentication HTTP errors on the existing failure path.
.github/scripts/sentry_to_github_issues.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +98 to +104
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Comment thread .github/scripts/sentry_to_github_issues.py
Co-authored-by: LightSage <46062298+LightSage@users.noreply.github.com>
@LightSage
LightSage merged commit ab23365 into master Aug 26, 2026
3 checks passed
@LightSage
LightSage deleted the copilot/fix-sync-job-failure branch August 26, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants