Skip to content

fix: fail with actionable errors on misconfigured verifier options - #136

Merged
tas50 merged 1 commit into
mainfrom
fix/actionable-config-errors
Aug 30, 2026
Merged

fix: fail with actionable errors on misconfigured verifier options#136
tas50 merged 1 commit into
mainfrom
fix/actionable-config-errors

Conversation

@tas50

@tas50 tas50 commented Aug 30, 2026

Copy link
Copy Markdown
Member

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.yml typo I could reproduce:

A list option written as a single mapping. install_modules, register_repository, bootstrap.modules and copy_folders are all documented as lists. Leave off the - and Array() turns the mapping into a list of [key, value] pairs. install_modules then generated, silently:

Write-host -NoNewline 'Installing [:Name, "PSScriptAnalyzer"] ...'
Install-Module -Name '[:Name, "PSScriptAnalyzer"]'

register_repository raised TypeError: no implicit conversion of Symbol into Integer from inside the verifier, and copy_folders raised TypeError out of File.join.

A mapping entry with no Name. install_modules raised NoMethodError: undefined method 'gsub' for nil. register_repository and bootstrap.modules emitted 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_folder that does not exist. Pathname#realpath raised Errno::ENOENT: No such file or directory @ rb_check_realpath_internal - tests, which mentions neither the option nor kitchen.yml. The README already tells people the folder has to exist; now the error does too.

A downloads entry with a blank value. NoMethodError: undefined method 'gsub' for nil.

All of them now raise Kitchen::UserError naming the option at fault and the shape it expects, e.g.:

The verifier's 'install_modules' must be a list, but a single mapping was given. Put a '- ' in front of each entry in kitchen.yml.

The verifier's 'test_folder' is set to 'tests/integration', which does not exist. It is resolved relative to the directory kitchen runs in, so give it a path that exists there or an absolute one.

No valid configuration changes behaviour. spec/kitchen/verifier/pester_config_errors_spec.rb pins each message and, next to it, the shapes that have to keep working — a list of mappings, a list of bare strings, and a Name given 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

$ bundle exec cookstyle --chefstyle
12 files inspected, no offenses detected

$ bundle exec rake test
164 runs, 341 assertions, 0 failures, 0 errors, 0 skips
Tests Passed: 17, Failed: 0, Skipped: 0

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>
@tas50
tas50 merged commit 43372d8 into main Aug 30, 2026
15 checks passed
@tas50
tas50 deleted the fix/actionable-config-errors branch August 30, 2026 02:22
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.

1 participant