fix(api): prevent Sentry alerts for GraphQL syntax errors#1602
fix(api): prevent Sentry alerts for GraphQL syntax errors#1602sentry[bot] wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
❌ 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Codecov Report❌ Patch coverage is
❌ 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:
|
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
curlcommands, leading to syntax like:String!instead of$varName:String!) were causingGraphQLSyntaxError.Previous Behavior:
These
GraphQLSyntaxErrorinstances were caught by the generic error handling inerror_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:
GraphQLSyntaxError: Ingraphql_api/views.py, theerror_formatternow explicitly checks forGraphQLSyntaxError.GraphQLSyntaxErroroccurs, it is now classified as a client error. The error message is returned to the client with atypeof"SyntaxError", and crucially, it is no longer logged as an internal server error or captured by Sentry.postmethod inAsyncGraphqlViewnow checks for errors oftype: "SyntaxError"in the response data and returns anHttpResponseBadRequest(HTTP 400) to the client. This provides clearer and more appropriate feedback for malformed requests, aligning with how other client-side errors (likeMissingVariablesErroror rate limits) are handled.Benefits:
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