fix: ensure router header expressions are set even on early return errors#2492
Conversation
WalkthroughThreads header propagation into router error paths, refactors error-writing to use a single params struct, and adds tests plus test modules for header propagation, response-write failures, and non-flusher-writer behavior. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
Router-nonroot image scan passed✅ No security vulnerabilities found in image: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2492 +/- ##
==========================================
+ Coverage 61.45% 61.70% +0.24%
==========================================
Files 229 229
Lines 23934 24022 +88
==========================================
+ Hits 14709 14823 +114
+ Misses 7968 7949 -19
+ Partials 1257 1250 -7
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@router-tests/header_propagation_test.go`:
- Around line 1534-1768: In TestHeaderPropagationOnErrorResponses, within the
"router response headers should be propagated on bad request errors" subtest,
check err returned from xEnv.MakeGraphQLRequest before accessing res (swap the
require.NoError(t, err) to immediately follow the call to
xEnv.MakeGraphQLRequest and move any uses of res or
res.Response.StatusCode/Headers after that check) so you don't dereference res
when the request failed; adjust assertions using res (require.Equal on
StatusCode and header checks) to occur after require.NoError.
In `@router/core/batch.go`:
- Around line 200-206: The batch-level error path omits header propagation:
update the call to writeRequestErrors to include headerPropagation in the
writeRequestErrorsParams (pass the handler's headerPropagation value into the
params, e.g., add headerPropagation: headerPropagation) so router-level response
header expressions are applied for batch parsing/validation failures; then
thread HeaderPropagation through the batch handler's constructor/HandlerOpts at
the call site that builds HandlerOpts (ensure the graph mux/wiring that
constructs HandlerOpts supplies the HeaderPropagation instance).
|
Moved to draft, as working on codecov changes |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@router/core/errors.go`:
- Around line 215-220: The call to params.logger in the error branch of
params.headerPropagation.ApplyRouterResponseHeaderRules can panic if
params.logger is nil; modify the block that calls ApplyRouterResponseHeaderRules
to check that params.logger != nil before calling params.logger.Error (or use a
safe fallback/no-op logger) so that logging the failure is guarded; ensure the
same nil-check pattern used in other branches of the surrounding function is
applied here for consistency with params.logger usage.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@router-tests/error_handling_test.go`:
- Around line 1715-1723: The test is ignoring the error returned by io.ReadAll
which can hide failures; update the test around the io.ReadAll call so you
capture its error and assert it was nil (e.g., replace "body, _ :=
io.ReadAll(resp.Body)" with code that calls io.ReadAll(resp.Body), stores the
error in a variable, and calls require.NoError(t, err) before asserting
require.Empty(t, body)); reference the io.ReadAll call and the
require.NoError/require.Empty assertions to locate the change.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@router-tests/http_subscriptions_test.go`:
- Around line 295-307: The test creates an http.Client with no timeout (client
:= http.Client{}) which can hang; update the client instantiation used in this
test to include a timeout consistent with other tests (e.g.,
http.Client{Timeout: time.Second * 100}) so requests and io.ReadAll(resp.Body)
cannot block indefinitely; ensure you import time if not already and keep the
rest of the test flow (req, resp, defer resp.Body.Close()) unchanged.
This PR fixes a bug where we do not process router response header expressions on early returns on errors, some of these errors are as follow
etc
In addition, we skip processing the header for early returns of subscription operation types, this is as we currently do not process the router response header expressions when the request is successful for subscriptions, so we dont process them when they are not successful either.
Due to refactoring code, codecov has highlighted quite a few places which did not have code coverage before, I have added tests for those as well. However a few still remain missing as they seem to be "unreachable", and might need more investigation / be covered by unit tests.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Tests (helpers)
Checklist