fix: fail with actionable errors on misconfigured verifier options - #136
Merged
Conversation
Every one of these is a plausible kitchen.yml typo that used to surface as
something unrelated, or not at all:
- `install_modules`, `register_repository`, `bootstrap.modules` and
`copy_folders` are lists. Written as a single YAML mapping -- easy to do,
it is one missing `- ` -- `Array()` turned the mapping into a list of
`[key, value]` pairs and we generated `Install-Module -Name '[:Name,
"PSScriptAnalyzer"]'` without complaint, or raised `TypeError: no implicit
conversion of Symbol into Integer` from inside the verifier.
- A mapping entry with no `Name` raised `NoMethodError: undefined method
'gsub' for nil` for `install_modules`, and for the other two emitted an
empty `${}` that failed on the instance a long way from its cause.
- A `test_folder` that does not exist raised `Errno::ENOENT: No such file or
directory @ rb_check_realpath_internal`, which names neither the option nor
kitchen.yml.
- A `downloads` entry with a blank value raised `NoMethodError: undefined
method 'gsub' for nil`.
They now raise `Kitchen::UserError` naming the option at fault and the shape
it expects. Valid configuration is unaffected, and there is a spec for each
message alongside the shapes that must keep working.
Signed-off-by: Tim Smith <tim@mondoo.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The verifier interpolates its config straight into PowerShell. When the config is wrong, the failure used to land somewhere unrelated — or not at all. Each of these is a plausible
kitchen.ymltypo I could reproduce:A list option written as a single mapping.
install_modules,register_repository,bootstrap.modulesandcopy_foldersare all documented as lists. Leave off the-andArray()turns the mapping into a list of[key, value]pairs.install_modulesthen generated, silently:register_repositoryraisedTypeError: no implicit conversion of Symbol into Integerfrom inside the verifier, andcopy_foldersraisedTypeErrorout ofFile.join.A mapping entry with no
Name.install_modulesraisedNoMethodError: undefined method 'gsub' for nil.register_repositoryandbootstrap.modulesemitted an empty${}into the generated script and failed on the instance, with a PowerShell parse error that says nothing about which entry caused it.A
test_folderthat does not exist.Pathname#realpathraisedErrno::ENOENT: No such file or directory @ rb_check_realpath_internal - tests, which mentions neither the option norkitchen.yml. The README already tells people the folder has to exist; now the error does too.A
downloadsentry with a blank value.NoMethodError: undefined method 'gsub' for nil.All of them now raise
Kitchen::UserErrornaming the option at fault and the shape it expects, e.g.:No valid configuration changes behaviour.
spec/kitchen/verifier/pester_config_errors_spec.rbpins each message and, next to it, the shapes that have to keep working — a list of mappings, a list of bare strings, and aNamegiven as a string key rather than a symbol.Deliberately untouched: the exit-code handling in
#invoke_pester_scriptblock, which is in flight in #109.Verification