Fix nested @catch: stop inner-handled errors from propagating#5341
Open
christiansany wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5339
The bug
When
@catchdirectives are nested, a field error handled by the inner@catchis also counted by the outer@catch, so the outer boundary fires even though, from its perspective, the inner field resolved successfully.@catch(to: RESULT): the outer field becomes{ ok: false }instead of{ ok: true, value: … }.@catch(to: NULL): the whole outer object is nulled instead of just the inner field.It compiles fine and fails silently at runtime. Full write-up and a runnable reproduction are in the linked issue (repro: christiansany/relay-playground#1).
The fix
In
RelayReader, whether a@catchboundary "saw" an error was based on_fieldErrorsbeing non-empty — but that list also contains errors already markedhandledby an inner@catch(they flow through only for logging). The fix excludes already-handled errors when deciding an outer boundary's outcome:_asResultnow builds its result from the unhandled errors only ({ ok: true }when none remain).NULLpath nulls the field only when there is an unhandled error (_fieldErrors.some(e => !e.handled)).An inner
@catchconsumes its error and the outer boundary no longer reacts to it. Errors that are genuinely unhandled at a given level still propagate exactly as before.Tests
Added regression tests in
RelayReader-CatchFields-test.jscovering both targets with a server error on the inner field:@catch(to: RESULT)→ outermeis{ ok: true, value: { lastName: { ok: false, … } } }(inner catches, outer succeeds).@catch(to: NULL)→{ me: { lastName: null } }(only the inner field nulled).In both cases the error is still surfaced once in
fieldErrorswithhandled: true.Testing
RelayReader-CatchFieldstests remain green.RelayReader.js(10 lines); no API or compiler changes.