diff options
author | Tim Smith <tsmith@chef.io> | 2017-12-29 20:37:39 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-12-29 20:46:31 -0800 |
commit | 601c2cabf9cd3101c624e86602a52df58d7b5d11 (patch) | |
tree | 5da749fafa256e46a659a4c841979d58c78ffe93 /lib/chef/property.rb | |
parent | bfe8487a26f99d3cd3e08fffea8cf6457631cf69 (diff) | |
download | chef-601c2cabf9cd3101c624e86602a52df58d7b5d11.tar.gz |
Improve property warnings in resourcesbetter_resource_errors
Give more details on why people are seeing these problems so they can fix them.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef/property.rb')
-rw-r--r-- | lib/chef/property.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb index a72e41a61e..9d0957dcdf 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -99,7 +99,7 @@ class Chef if options.has_key?(:name_attribute) # If we have both name_attribute and name_property and they differ, raise an error if options.has_key?(:name_property) - raise ArgumentError, "Cannot specify both name_property and name_attribute together on property #{self}." + raise ArgumentError, "name_attribute and name_property are functionally identical and both cannot be specified on a property at once. Use just one on property #{self}" end # replace name_property with name_attribute in place options = Hash[options.map { |k, v| k == :name_attribute ? [ :name_property, v ] : [ k, v ] }] @@ -107,7 +107,7 @@ class Chef end if options.has_key?(:default) && options.has_key?(:name_property) - raise ArgumentError, "Cannot specify both default and name_property/name_attribute together on property #{self}" + raise ArgumentError, "A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property #{self}" end # Recursively freeze the default if it isn't a lazy value. @@ -361,7 +361,7 @@ class Chef end if value.nil? && required? - raise Chef::Exceptions::ValidationFailed, "#{name} is required" + raise Chef::Exceptions::ValidationFailed, "#{name} is a required property" else value end @@ -386,7 +386,7 @@ class Chef value = set_value(resource, input_to_stored_value(resource, value)) if value.nil? && required? - raise Chef::Exceptions::ValidationFailed, "#{name} is required" + raise Chef::Exceptions::ValidationFailed, "#{name} is a required property" else value end @@ -457,7 +457,7 @@ class Chef # options. # # @param resource [Chef::Resource] The resource we're validating against - # (to provide context for the validate). + # (to provide context for the validation). # @param value The value to validate. # # @raise Chef::Exceptions::ValidationFailed If the value is invalid for @@ -514,18 +514,18 @@ class Chef # very confusing results. if property_redefines_method? resource_name = declared_in.respond_to?(:resource_name) ? declared_in.resource_name : declared_in - raise ArgumentError, "Property `#{name}` of resource `#{resource_name}` overwrites an existing method." + raise ArgumentError, "Property `#{name}` of resource `#{resource_name}` overwrites an existing method. A different name should be used for this property." end # We prefer this form because the property name won't show up in the # stack trace if you use `define_method`. declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1 def #{name}(value=NOT_PASSED) - raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given? + raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given? self.class.properties[#{name.inspect}].call(self, value) end def #{name}=(value) - raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given? + raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given? self.class.properties[#{name.inspect}].set(self, value) end EOM |