diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-10-31 15:45:21 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-10-31 15:45:21 -0700 |
commit | b6f81d6f6702f5f13e3e0307c8253d1ef949645b (patch) | |
tree | ac7d95b3c5d5321932ab8485d5d765500b139501 | |
parent | fc30a44a383f5742236110002580d0c40380718c (diff) | |
download | chef-b6f81d6f6702f5f13e3e0307c8253d1ef949645b.tar.gz |
improve property-resource namespace collision exception
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/property.rb | 8 | ||||
-rw-r--r-- | spec/integration/recipes/resource_action_spec.rb | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb index a357ba9ee3..9433326b5b 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -522,22 +522,22 @@ class Chef # 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} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." 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} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." 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 rescue SyntaxError # If the name is not a valid ruby name, we use define_method. declared_in.define_method(name) do |value = NOT_PASSED, &block| - raise "Property #{name} of #{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block + 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 self.class.properties[name].call(self, value) end declared_in.define_method("#{name}=") do |value, &block| - raise "Property #{name} of #{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block + 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 self.class.properties[name].set(self, value) end end diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb index 60d5831a50..f11696bae4 100644 --- a/spec/integration/recipes/resource_action_spec.rb +++ b/spec/integration/recipes/resource_action_spec.rb @@ -498,7 +498,7 @@ module ResourceActionSpec it "Raises an error when attempting to use a template in the action" do expect_converge do has_property_named_template "hi" - end.to raise_error(/Property template of has_property_named_template\[hi\] cannot be passed a block! If you meant to create a resource named template instead, you'll need to first rename the property./) + end.to raise_error(/Property `template` of `has_property_named_template\[hi\]` was incorrectly passed a block. Possible property-resource collision. To call a resource named `template` either rename the property or else use `declare_resource\(:template, ...\)`/) end end |