8000 Allow visit function to return errors in structwalk.WalkType by shreyas-goenka · Pull Request #3034 · databricks/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 12 commits into from
Jun 11, 2025

Conversation

shreyas-goenka
Copy link
Contributor
@shreyas-goenka shreyas-goenka commented Jun 11, 2025

Changes

This PR:

  1. Propogates errors up the stack when an error is returned by the visit function.
  2. Adds 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.

@shreyas-goenka shreyas-goenka changed the title Allow errors in strutctwalk.WalkType; add ErrSkipWalk Allow visit function to return errors in strutctwalk.WalkType Jun 11, 2025
@shreyas-goenka shreyas-goenka changed the title Allow visit function to return errors in strutctwalk.WalkType Allow visit function to return errors in structwalk.WalkType Jun 11, 2025
@shreyas-goenka shreyas-goenka marked this pull request as ready for review June 11, 2025 13:56
@@ -27,7 +27,9 @@ import (
//
// ******************************************************************************************************

type VisitTypeFunc func(path *structpath.PathNode, typ reflect.Type)
type VisitTypeFunc func(path *structpath.PathNode, typ reflect.Type) error
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@shreyas-goenka shreyas-goenka merged commit 92ea5b2 into main Jun 11, 2025
9 of 10 checks passed
@shreyas-goenka shreyas-goenka deleted the skip-walk branch June 11, 2025 15:34
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.

2 participants
0