Skip to content

fix: report every invalid object field in one validation error - #594

Open
mvanhorn wants to merge 2 commits into
convex:mainfrom
mvanhorn:fix/591-validation-error-all-fields
Open

mvanhorn wants to merge 2 commits into
convex:mainfrom
mvanhorn:fix/591-validation-error-all-fields

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

That branch now collects every field error and, when there is only one, returns the original variant so its message stays the same. Several errors are returned as ValidationError::Multiple, formatted as a bullet per problem with that problem's path and one object and validator summary. Nested Multiple errors are flattened into the parent, with each child receiving the parent path segment. An array still stops at its first bad element, and a union of object shapes still fails as a single NoMatch. When an object fails validation in more than one field, the caller only sees the first problem. A wrong type, a missing required field, and an extra field are reported one at a time, so a payload has to be fixed and submitted again to surface each remaining mismatch. The object branch of check_value_internal returns as soon as one field fails. A nested validator error is propagated with ?, and a missing required field or an extra field returns Err before the rest of the object is checked. The common crate tests passed, covering the new object-validator error cases.

Fixes #591

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

That branch now collects every field error and, when there is only one,
returns the original variant so its message stays the same. Several
errors are returned as ValidationError::Multiple, formatted as a bullet
per problem with that problem's path and one object and validator
summary. Nested Multiple errors are flattened into the parent, with each
child receiving the parent path segment. An array still stops at its
first bad element, and a union of object shapes still fails as a single
NoMatch.

Fixes convex#591

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/common/src/schemas/validator.rs Resolved
A missing or extra field's context points at its parent object, so a
nested bullet only showed the parent path. Add the field name to the
path, and cover it with a nested test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation error only reports a single property

1 participant