fix: fix nesting issue due to the errors order #824
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.
This fixes a nesting issue I've originally hit with the ajv resolver (albeit the issue itself is applicable to all resolvers) which is that
toNestErrorsmay lose keys depending on the order of the keys returned by theparseErrorSchema, e.g. in this particular example the error for theconfigis actually last (the console output ofparsedErrorsis sorted thus a bit misleading) and simply replaces theconfig: { type: …, userId: … }object that existed one nesting step earlier —I was explaining this to my coworkers so I have a screencast (100 seconds) that illustrates the issue, attaching it here in hope that it'd explain the changes behind the PR better than my writing —
resolvers.mp4
Also I was not very comfortable with passing the objects straight to
Object.assign, I think I've hit a bug with objects being mutated in place, so even though I can no longer reproduce it I've still wrapped "foreign" objects in astructuredClone, just to be on a safe side.