Skip to content

fix(repositories): Silence github errors when performing auto-sync#114650

Open
wedamija wants to merge 1 commit intomasterfrom
danf/sync-repos-github-override
Open

fix(repositories): Silence github errors when performing auto-sync#114650
wedamija wants to merge 1 commit intomasterfrom
danf/sync-repos-github-override

Conversation

@wedamija
Copy link
Copy Markdown
Member

@wedamija wedamija commented May 1, 2026

This more explicitly handles some github related errors and allows us to silence them

Fixes SENTRY-5NAF

This more explicitly handles some github related errors and allows us to silence them

Fixes SENTRY-5NAF
@wedamija wedamija requested a review from a team May 1, 2026 22:26
@wedamija wedamija requested review from a team as code owners May 1, 2026 22:26
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 1, 2026
Comment on lines 224 to 234

def is_broken_integration_error(self, exc: Exception) -> HaltReason | None:
if isinstance(exc, ApiForbiddenError) and "suspended" in str(exc):
return "installation_suspended"
if isinstance(exc, ApiForbiddenError):
if self.is_rate_limited_error(exc):
return "rate_limited"
if "suspended" in str(exc):
return "installation_suspended"
return "unauthorized"
return super().is_broken_integration_error(exc)

def message_from_error(self, exc: Exception) -> str:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The ApiForbiddenError handling for repo auto-sync was not applied to GitHubEnterpriseIntegration, causing syncs to fail for GHE instead of silently halting on certain permission errors.
Severity: MEDIUM

Suggested Fix

Update GitHubEnterpriseIntegration.is_broken_integration_error in src/sentry/integrations/github_enterprise/integration.py to mirror the logic in GitHubIntegration.is_broken_integration_error. It should handle ApiForbiddenError by returning 'unauthorized' to ensure the sync process halts gracefully.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/sentry/integrations/github/integration.py#L223-L234

Potential issue: The fix to silently halt on `ApiForbiddenError` during repository
auto-sync was only applied to `GitHubIntegration` and not its counterpart,
`GitHubEnterpriseIntegration`. For GitHub Enterprise, an `ApiForbiddenError` that is not
related to a suspended account (e.g., an IP allowlist block) will not be correctly
handled by `is_broken_integration_error`. The error propagates up to `sync_repos.py`,
where it is re-raised, causing the sync process to fail for the integration instead of
being silently halted.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant