Skip to content

Populate fieldPath on relay_field_payload.error events - #5427

Open
kevin9327 wants to merge 1 commit into
facebook:mainfrom
kevin9327:fix/field-payload-error-path
Open

kevin9327 wants to merge 1 commit into
facebook:mainfrom
kevin9327:fix/field-payload-error-path

Conversation

@kevin9327

Copy link
Copy Markdown

Fixes #4970.

Problem

relay_field_payload.error events always had fieldPath: '' in real apps, so relayFieldLogger and the @throwOnFieldError message ("Received a field error in the server response for field ''") never said which field failed.

RelayReader._maybeAddFieldErrors built the path from error.path. But RelayErrorTrie drops path when the normalizer attaches an error to a record (see the __errors expectations in RelayResponseNormalizer-test), so in practice the join was always empty. The reader tests passed only because they wrote records by hand with an absolute path on the stored error.

Fix

Build the path the same way the reader already does for missing_expected_data / missing_required_field: start from the field's name (alias or name), and let _prependPreviousErrors add the parent fields as the reader unwinds. The path is therefore relative to the fragment/operation that owns the event, like the other kinds.

Tests

  • New RelayReader-RelayErrorHandling-test case: normalizes a real response with a server error at ['me', 'lastName'] through RelayResponseNormalizer, then reads it. It fails before (fieldPath: '') and passes after ('me.lastName').
  • Updated existing expectations that encoded the empty path or the hand-written absolute path:
    • observeQuery / observeFragment: field '' → field 'me.name' / 'name'.
    • The "noncompliant lists" cases: '' → node.friends.edges / node.emailAddresses.
    • Fragment-level tests now report the fragment-relative path (name, lastName, nodes.0.lastName).
    • Aliased inline fragment (@catch) cases now include the alias (me.myAlias.lastName), same as missing-data events.

yarn jest packages: 246 suites, 3824 passed. ESLint and Prettier are clean on the changed files. I couldn't run flow check meaningfully on my partial checkout.

I used an AI assistant to help with this change. I traced the bug, reproduced it with the normalizer and reviewed the fix and test updates myself.

The normalizer strips `path` from server errors when it attaches them to a
record, so the reader's `(error.path ?? []).join('.')` was always '' in
practice. Build the path the same way as for missing data / @required
errors: start from the field name and prepend parents via
_prependPreviousErrors.

Fixes facebook#4970
@meta-cla meta-cla Bot added the CLA Signed label Oct 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fieldPath is always empty string on relay_field_payload.error

1 participant