fix: keep error data when formatErrors receives an error from a duplicate module copy - #18429
Open
sarmah-rup wants to merge 1 commit into
Open
sarmah-rup wants to merge 1 commit into
sarmah-rup wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Bug
In a production build, REST error responses can lose
data(for example a ValidationError'sdata.errorswith the field paths). The status and message come through, butformatErrorsreturns{ errors: [{ message }] }. This happens when the error was thrown by a different bundled copy of payload than the one runningformatErrors, which #18420 traces to the route handler and page layers each getting their own copy.Root cause
On 3.x,
formatErrorsonly keepsdatawhenincoming instanceof ValidationError || incoming instanceof APIError. Errors created by another copy of the module have different class identities, so both checks are false. The Mongoose fallback doesn't match either, since it comparesname, which is minified. The error falls through to the message-only branch.Solution
Backport the check that
mainalready has: alongsideinstanceof, accept any error withisOperational === true(set inExtendableError's constructor for every Payload error) that carriesdata. Behaviour for real instances is unchanged. This restoresdata. It does not touch the minifiedname(#13645), which is a separate problem.Fixes #18420
Testing
should keep data for a Payload error thrown by another copy of the error classestopackages/payload/src/utilities/formatErrors.spec.ts. It builds a ValidationError-shaped error from an unrelated class with a minified name. It fails on3.x(nodatain the result) and passes with this change.formatErrors.spec.ts: 8/8 passing.vitest run --project unit packages/payload/: 974/977 passing. The 3 failures aresrc/bin/index.spec.ts(CLI exit codes) and fail the same way without this change in my local setup.tsc --noEmitfor packages/payload passes.