Skip to content

fix(api): prevent Sentry alerts for GraphQL syntax errors#1602

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/api-graphql-syntax-error
Open

fix(api): prevent Sentry alerts for GraphQL syntax errors#1602
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/api-graphql-syntax-error

Conversation

@sentry

@sentry sentry Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an issue where client-side GraphQL syntax errors were being incorrectly reported as internal server errors and captured by Sentry.

Root Cause:
Malformed GraphQL queries originating from clients (e.g., due to unescaped shell variables in curl commands, leading to syntax like :String! instead of $varName:String!) were causing GraphQLSyntaxError.

Previous Behavior:
These GraphQLSyntaxError instances were caught by the generic error handling in error_formatter, resulting in them being logged as "GraphQL internal server error" and sent to Sentry. This created unnecessary noise in Sentry for issues that were not actual server-side bugs.

Changes Made:

  1. Explicitly Handle GraphQLSyntaxError: In graphql_api/views.py, the error_formatter now explicitly checks for GraphQLSyntaxError.
  2. Client Error Classification: When a GraphQLSyntaxError occurs, it is now classified as a client error. The error message is returned to the client with a type of "SyntaxError", and crucially, it is no longer logged as an internal server error or captured by Sentry.
  3. HTTP 400 Response: The post method in AsyncGraphqlView now checks for errors of type: "SyntaxError" in the response data and returns an HttpResponseBadRequest (HTTP 400) to the client. This provides clearer and more appropriate feedback for malformed requests, aligning with how other client-side errors (like MissingVariablesError or rate limits) are handled.

Benefits:

  • Reduces Sentry noise by preventing alerts for client-originated syntax errors.
  • Provides more accurate HTTP status codes and error messages to clients for invalid GraphQL queries.

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-EJK

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.82%. Comparing base (9d430bf) to head (1b68fdd).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/codecov-api/graphql_api/views.py 50.00% 3 Missing ⚠️

❌ Your patch check has failed because the patch coverage (50.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1602      +/-   ##
==========================================
- Coverage   91.83%   91.82%   -0.01%     
==========================================
  Files        1328     1328              
  Lines       51379    51384       +5     
  Branches     1647     1647              
==========================================
+ Hits        47182    47184       +2     
- Misses       3875     3878       +3     
  Partials      322      322              
Flag Coverage Δ
apiunit 94.79% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codecov-notifications

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/codecov-api/graphql_api/views.py 50.00% 3 Missing ⚠️

❌ Your patch check has failed because the patch coverage (50.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

0 participants