-
Notifications
You must be signed in to change notification settings - Fork 57
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
Fix metadata computation for empty bundle #939
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are multiple load modes necessary?
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.
No, infact there probably wont be multiple modes anytime soon. The reason I went with this approach is this is more readable at the call site:
The alternatives add a boolean field arg (not readable at call site) or a enum for the "goal/mode" of load which also did non seem like a good fit here.
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.
Oh I see, it's for zero or one. We can change the callsite to be explicit ("ErrorOnEmptyState") or have two public methods, one with one parameter and one with no parameters. What do you think?
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.
Exactly it's zero to one. I'm against having two methods because there's no need for it, most of the code would be dup.
Between
ErrorOnEmptyState
andNoErrorOnEmptyState
, I am ok with either. I preferNoErrorOnEmptyState
here because the branching is clearer in that case. Note, we cannot callTerraformToBundle
if the state is empty. .Would renaming the mode to
AllowEmptyState
be more readable?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.
As a general rule, don't use negatives in constant names because double negatives read odd. I.e. if I write
if !NoErrorOnFoo
is harder to parse thanif ErrorOnFoo
.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.
You only need two Load methods, essentially two constructors.
The main validation logic could still be the same. This approach just seems unnecessarily generic for what we're trying to do here.
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.
We follow this pattern of variadic args for 0/1 modes in other places too. For example:
cli/libs/filer/filer.go
Lines 17 to 21 in d70d744
IMO it's better to expose a single public method here, and allow users to toggle the validation they require using the mode arg. Two public APIs seem unnecessary even if the most the code would be common.
I have refactored the code to use
ErrorOnEmptyState
instead though now.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.
Ok, happy to go with precedent if it exists. I guess this kind of pattern is used for functional options too. Given that this is also quasi-internal to DABs, maybe it is fine.
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.
I guess I'm a purist, but to me, it doesn't feel good to allow users to call functions in meaningless ways (in this case, with 2 or more values for this option). I'm pro-referential transparency, pro-"expose the exact interface you permit".