Validate config values for arrays and hashes #898
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.
Motivation
Since we write Tapioca config as a YAML file, it's easy to make type errors that will result in unexpected behaviors.
For example, even if this config file looks ok, the
msgpack
gem will not be turnedtyped: false
:Because we expect the values inside the
typed_overrides
hash to be strings rather than booleans.This actually happened today to one of our users: #895 (comment). Having an error message earlier would have saved both of us some time and confusion.
Implementation
The solution choose here seems a bit hack-ish but we can't rely on Thor expected types for the content of
:array
and:hash
options:Once we validated all others criteria for options keys and values we add an additional check for arrays and hashes to make sure the values (and keys in the case of a hash) are all of the type
String
.Even if rather limited, this works in practice because the only arrays and hashes we take in the config always expect string (iirc?).
I guess we can revisit this later if we add different options but I'm open to better suggestions.
Tests
See automated tests.