Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structured field and rule paths, field and rule values to ValidationErrors #154

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jchadwick-buf
Copy link
Member

@jchadwick-buf jchadwick-buf commented Oct 15, 2024

This implements the structured field and rule paths, passing the conformance test changes in bufbuild/protovalidate#265.

In addition, it also adds the ability to get the field and rule values. These are not present in the protobuf form of the violation.

The API is still heavily centered around the protobuf form of violations, but the ValidationError type is no longer an alias to the protobuf buf.validate.Violations message. The intention is that users needing access to the error information will still use the proto violations message, only using the "native" interface methods to access in-memory data that is not feasible to transport over the wire. (e.g. protoreflect.Value pointers.)

DO NOT MERGE: Need to revert e948b95 and update the protovalidate dependency when bufbuild/protovalidate#265 is merged.

Copy link

github-actions bot commented Oct 15, 2024

The latest Buf updates on your PR. Results from workflow Buf / validate-protos (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedNov 7, 2024, 12:08 AM

@jchadwick-buf jchadwick-buf marked this pull request as draft October 22, 2024 16:02
@jchadwick-buf jchadwick-buf changed the title Refactor validation errors Add structured field and rule paths, field and rule values to ValidationErrors Nov 6, 2024
@jchadwick-buf jchadwick-buf marked this pull request as ready for review November 7, 2024 00:10
@jchadwick-buf
Copy link
Member Author

Well, it took a while, but I think this is the most bang-for-our-buck possible. I think it's not the best possible code by any single measure, but I tried to balance concerns of performance, simplicity and API surface. A lot of thought was put into exactly how paths are constructed: as before, we avoid constructing paths unless a validation error is actually encountered. A careful adjustment is made to the builder code to add just enough information to be able to produce the rule paths accurately in as many edge cases as I could find, without requiring new special cases to be distributed in more places. To minimize the resulting API surface of changing the error type, the protobuf form of a Violation is still the primary way to consume a Violation, and we only need to add a utility function and an additional type to the protovalidate package.

It would be difficult to convey the number of different considerations that wound up needing to be made, but hopefully the resulting code does not make this difficulty apparent. :)

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.

1 participant