-
Notifications
You must be signed in to change notification settings - Fork 91
Allow visit function to return errors in structwalk.WalkType #3034
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
Conversation
libs/structwalk/walktype.go
Outdated
@@ -27,7 +27,9 @@ import ( | |||
// | |||
// ****************************************************************************************************** | |||
|
|||
type VisitTypeFunc func(path *structpath.PathNode, typ reflect.Type) | |||
type VisitTypeFunc func(path *structpath.PathNode, typ reflect.Type) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be simpler? We don't care about errors, just need skipping, so we can return bool: true to continue, false to skip.
The error propagation can really be done by the caller however they like (e.g. append diagnostics), no need to complicate visit logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I've updated the function to return a boolean. I flipped the semantics though because skipping on true seemed cleaner.
Changes
This PR:
ErrSkipWalk
which can be returned by a skip function to skip walking that type entirely.Why
This is needed for required code-generation because we wish to avoid walking some internal structs like like Locations where otherwise we end up consider fields in it as required.
Tests
New unit tests.