Skip to content

fix(sentry): keep scope validation alive when Sentry returns an empty error body - #6814

Closed
L4XB wants to merge 1 commit into
keephq:mainfrom
L4XB:fix/sentry-validate-scopes-empty-body
Closed

fix(sentry): keep scope validation alive when Sentry returns an empty error body#6814
L4XB wants to merge 1 commit into
keephq:mainfrom
L4XB:fix/sentry-validate-scopes-empty-body

Conversation

@L4XB

@L4XB L4XB commented Sep 11, 2026

Copy link
Copy Markdown

Closes #6812.

What happened

SentryProvider.validate_scopes() called response.json() on every non-OK response. Sentry answers the deprecated /plugins/webhooks/ endpoint used for the project:write check with a 404 and an empty text/html body, so response.json() raised JSONDecodeError, the exception escaped validate_scopes, and the UI showed "Failed to revalidate scopes" with every scope on "Not checked" even though the provider was connected and pulling alerts.

Change

A small helper _scope_failure_detail(response) reads detail from a JSON body when there is one and otherwise falls back to HTTP <status>; the four failure sites (event:read with and without a configured project, project:read, project:write) use it. A single bad response now marks only its own scope, and a JSON error without detail reports the status instead of storing None.

Not changed: the /plugins/webhooks/ endpoint itself. Whether the project:write check should move to a non-legacy endpoint is a separate question; with this fix it degrades to "HTTP 404" for that scope instead of breaking the others.

Tests

New tests/test_sentry_provider.py builds a SentryProvider from a ProviderConfig and patches requests.get/requests.post with real requests.Response objects, so .ok and .json() behave as on the wire:

  • 404 with an empty text/html body on the webhook POST → {"event:read": True, "project:read": True, "project:write": "HTTP 404"}
  • 403 with a JSON detail → the detail text is reported as before
  • 401 with JSON but no detail"HTTP 401" for every scope
pytest tests/test_sentry_provider.py   # 3 passed
ruff check / ruff format --check (ruff 0.11.4 as pinned)   # clean

… error body

validate_scopes called response.json() on every failed request. Sentry
answers the deprecated /plugins/webhooks/ endpoint with a 404 and an empty
text/html body, so the JSONDecodeError escaped, the whole validation
failed and every scope showed "Not checked" even though the provider was
connected and pulling alerts.

Read the failure detail through one helper that falls back to "HTTP <code>"
when the body is not JSON or carries no detail, and use it at all four
sites so a single bad response only marks its own scope.
@CLAassistant

CLAassistant commented Sep 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@L4XB

L4XB commented Sep 13, 2026

Copy link
Copy Markdown
Author

Closing as superseded: #6813 landed the production fix for #6812 first, and its _extract_error_detail covers everything my _scope_failure_detail did plus the non-dict JSON case. No reason for a second implementation.

The half that is still missing is the tests — #6813 merged without any, and there is no test file for this provider on main. I have reopened that part as #6821, rewritten against _extract_error_detail as merged rather than against my own version.

@L4XB L4XB closed this Sep 13, 2026
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.

Bug: Sentry provider validate_scopes crashes on empty response body from /plugins/webhooks/

2 participants