Skip to content

Conversation

@danielhochman
Copy link
Contributor

Updated version of #455 using two methods Validate() and ValidateAll() instead of moving to a single method Validate(all bool). This retains compatibility with the existing interface checks in other modules such as:

type validator interface {
  Validate() error
}

if v, ok := message.(validator); ok {
  v.Validate()
}

Fixes #47

Co-authored-by: Mateusz Czapliński mateusz.czaplinski@wpengine.com

This reverts commit 758c5fc.

Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
… multierror-validation

Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
@danielhochman danielhochman marked this pull request as ready for review May 6, 2021 15:56
brandoncole
brandoncole previously approved these changes May 7, 2021
}
// AllErrors returns a list of validation violation errors.
func (m {{ multierrname . }}) AllErrors() []error { return m }

Choose a reason for hiding this comment

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

For nested scenarios, I wonder if it's worth adding a message that returns all errors recursively as well to completely flatten a tree of errors? If you feel like that complexity might be too much to implement here I'm more than happy to agree that it should be implemented in clients b/c this is already a great step.

Copy link
Contributor

@akavel akavel May 11, 2021

Choose a reason for hiding this comment

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

Thing is, such a func is quite complex, and yet basically 100% operates on interfaces (doesn't need to be specialized per-error-type), so IMO it doesn't need to be a method, and potentially it could be put as a "helper" func in an external package, e.g. a subpackage of PGV for being imported separately. Still, I think it could make quite a lot of sense to add such a func (or even method if really insisted), maybe with a "walker/visitor"-like signature, but I'd personally vote for working on one in a separate PR. And @brandoncole if you're really interested in this topic, maybe you'd like to try your hand at writing such a PR yourself? 🙂

Choose a reason for hiding this comment

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

I like that suggestion, it would cut down on the boilerplate and I agree it could probably just be a centrally defined function.

Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
@akonradi
Copy link
Contributor

akonradi commented May 7, 2021

I found this much easier to review relative to 5ef93ae, right before reverting take 1 of this. Even containing all the changes from dd3f943, the diff is tiny! danielhochman/protoc-gen-validate@5ef93ae...multierror-validation

@akonradi
Copy link
Contributor

akonradi commented May 7, 2021

This looks good to me, but I've also been wrong very recently. @akavel you're obviously an interested party, please feel free to chime in. I'm happy to merge this but holding off for a few days so anyone else following #47 has a chance to comment.

@brandoncole
Copy link

Just wanted to say thank you once again to all the folks involved in this great work 🙏

Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
}
// AllErrors returns a list of validation violation errors.
func (m {{ multierrname . }}) AllErrors() []error { return m }
Copy link
Contributor

@akavel akavel May 11, 2021

Choose a reason for hiding this comment

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

Thing is, such a func is quite complex, and yet basically 100% operates on interfaces (doesn't need to be specialized per-error-type), so IMO it doesn't need to be a method, and potentially it could be put as a "helper" func in an external package, e.g. a subpackage of PGV for being imported separately. Still, I think it could make quite a lot of sense to add such a func (or even method if really insisted), maybe with a "walker/visitor"-like signature, but I'd personally vote for working on one in a separate PR. And @brandoncole if you're really interested in this topic, maybe you'd like to try your hand at writing such a PR yourself? 🙂

Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
akavel
akavel previously approved these changes May 11, 2021
Copy link
Contributor

@akavel akavel left a comment

Choose a reason for hiding this comment

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

LGTM, thank you so much @danielhochman ! ❤️ 🚀

Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>
@danielhochman danielhochman force-pushed the multierror-validation branch from cf0a60b to 8e80c7b Compare May 11, 2021 20:48
@danielhochman
Copy link
Contributor Author

@akonradi ready to go!

@akonradi akonradi merged commit ff16dc3 into bufbuild:main May 13, 2021
@akonradi
Copy link
Contributor

Thanks, all!

@akavel
Copy link
Contributor

akavel commented May 13, 2021

Huge thanks @danielhochman for stepping in, following up with a new version and taking it up to the end! ❤️

regeda added a commit to regeda/go-grpc-middleware that referenced this pull request Oct 22, 2021
protoc-gen-validate is release under the v0.6.2:

https://github.com/envoyproxy/protoc-gen-validate/releases/tag/v0.6.2

The release contains the merge PR about "multi-error validation with
ValidateAll()":

bufbuild/protoc-gen-validate#468
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.

Return list of validation errors instead of first failed

5 participants