summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-10-07 13:25:03 -0700
committerTim Smith <tsmith@chef.io>2018-10-31 14:24:03 -0700
commite1b064ae64a60f31d31e66d19d31625217567d51 (patch)
tree48f98377ffd30ed4c41c1fd89c6ec5e6cc558348
parentabd710ebbaabeabd0f210963f3c4a9645bc1bf78 (diff)
downloadchef-e1b064ae64a60f31d31e66d19d31625217567d51.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.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb
index c955dd3b12..b7597d2dee 100644
--- a/lib/chef/mixin/params_validate.rb
+++ b/lib/chef/mixin/params_validate.rb
@@ -178,7 +178,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