Skip to content

fix(graphql): prevent client validation errors from being sent to Sentry - #2238

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/graphql-validation-sentry-IUGTNW
Open

fix(graphql): prevent client validation errors from being sent to Sentry#2238
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/graphql-validation-sentry-IUGTNW

Conversation

@sentry

@sentry sentry Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Previously, GraphQL validation errors (e.g., missing subfield selections, invalid syntax) were sometimes incorrectly logged as internal server errors and captured by Sentry.

The error_formatter in graphql_api/views.py had a narrow heuristic ("Cannot query field" in message) to identify client-side malformed queries. Other validation errors, like "Field 'repositories'... must have a selection of subfields", would fall through and be treated as server-side exceptions.

This change modifies the error_formatter to correctly identify all GraphQL validation errors. These errors consistently have original_error set to None by the GraphQL engine. By checking for original_error is None, we can now reliably distinguish client-side query mistakes from actual server-side exceptions. These client errors are now returned directly to the client via format_error without being logged as server errors or sent to Sentry.

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes API-F1C

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@thomasrockhu-codecov

thomasrockhu-codecov commented Sep 11, 2026

Copy link
Copy Markdown
Contributor
✨ Harness AI Code Review View in Harness →

🛑 Risk: MEDIUM

This PR reworks error_formatter in graphql_api/views.py so GraphQL validation/syntax errors (which have original_error is None) are returned directly to the client instead of being masked as INTERNAL SERVER ERROR and captured to Sentry. The core fix is sound, but it has a side effect the diff doesn't account for: Cannot query field errors now reach anonymous users unmasked, which reverses prior behavior and breaks the existing test_when_bad_query_and_anonymous test. Fix that first — either update the test to the new intended behavior or re-gate anonymous field-name disclosure.

Top findings

  • HIGH · TEST-GAP apps/codecov-api/graphql_api/views.py:353 — New original_error is None early return exposes bad-field errors to anonymous users and breaks test_when_bad_query_and_anonymous (asserts INTERNAL SERVER ERROR).
  • MEDIUM · SIMPLIFICATION apps/codecov-api/graphql_api/views.py:359 — Legacy is_bad_query branch is now unreachable dead code; remove it and the now-unused user/is_anonymous locals.

@sentry

sentry Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ Seer needs additional GitHub permissions

Seer wants to keep iterating on this pull request to get CI passing, but the Sentry GitHub App installation is missing permissions it needs to read the failing checks and push a fix.

Review and accept the updated permissions to let Seer continue: https://github.com/organizations/codecov/settings/installations/86101127/permissions/update

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.

1 participant