diff options
author | Tim Smith <tsmith@chef.io> | 2018-10-07 13:25:03 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-10-11 14:15:51 -0700 |
commit | ad72bd244a9a9ca73edc0fded0c26a76081d4710 (patch) | |
tree | d3b0d5e5cd31029d50f3c69a6abf2c00da8b96d7 | |
parent | 0c8f73047924ef49dc7b7bccdfb3325b15219d19 (diff) | |
download | chef-ad72bd244a9a9ca73edc0fded0c26a76081d4710.tar.gz |
Throw better error on invalid resources actions
Right now if a user enters an incorrect action they get a message like
this that doesn't print the actions as being symbols. That's super
confusing to new users and results in random cookbook bugs from time to
time.
[2018-10-07T13:26:39-07:00] FATAL: Chef::Exceptions::ValidationFailed: Option action must be equal to one of: nothing, create, remove, modify, manage, lock, unlock! You passed :whatever.
With this change we properly print out symbols as symbols so it's clear
what the available values are.
[2018-10-07T13:24:09-07:00] FATAL: Chef::Exceptions::ValidationFailed: Option action must be equal to one of: :nothing, :create, :remove, :modify, :manage, :lock, :unlock! You passed :whatever.
It's a small thing, but I think this will have a pretty big impact on
first time users. This one tripped me up when I first started.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index f77adecd60..8a5f27c8fa 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -174,7 +174,9 @@ class Chef to_be.each do |tb| return true if value == tb end - raise Exceptions::ValidationFailed, _validation_message(key, "Option #{key} must be equal to one of: #{to_be.join(", ")}! You passed #{value.inspect}.") + # Ruby will print :something as something, which confuses users so make sure to print them as symbols + corrected_type_array = to_be.collect { |x| x.kind_of?(Symbol) ? ":#{x}" : x } + raise Exceptions::ValidationFailed, _validation_message(key, "Option #{key} must be equal to one of: #{corrected_type_array.join(", ")}! You passed #{value.inspect}.") end end |