don't fail on undef variable in merge #147
Merged
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.
I'll explain the change, why I'd like it, and how I implemented it in the following.
EDIT: sorry, it should only concern commit 3077d26, not all three.
Proposed change:
if merge gets passed an undefined variable, it doesn't fail with an exception, but instead silently ignores the value
Use case:
In my configuration file, one parameter can be repeatedly set with different values. Both key and value are variable, so I use a hash. Based on the input, different values are used, so I create multiple hashes, combine them with merge and then pass them to the template as one (the template is part of a more generic puppet module and should not know about the different internal hashes I created).
Because some value are used, merge fails and I would have to check first for all combinations and then call merge in the right way.
I have three hashes to combine so I already have to check for nine combinations, for somebody with more it's even less feasible.
I'll sketch the code here:
Code change:
Add a check for .empty? for every argument. Good, because it filters everything that is not empty: string, lists, ... . Bad, because you could get away with passing a wrong type in some cases, get an exception in others. Unfortunately, puppets undef doesn't seem to map to anything useful in ruby. We can use arg == "", but that's only slightly better.
Any other ideas are most welcome!