summaryrefslogtreecommitdiff
path: root/lib/chef/property.rb
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-12-10 09:18:15 -0800
committerJohn Keiser <john@johnkeiser.com>2015-12-10 14:55:20 -0800
commit1910740592068982a4b6f9ee58452375d60281d5 (patch)
tree58e358d3911f769ea3052a14b8e1bc2747b56378 /lib/chef/property.rb
parentd8a869814a0cbe1a44ee47e5c3ac1802a8fef2f2 (diff)
downloadchef-1910740592068982a4b6f9ee58452375d60281d5.tar.gz
Warn when user sets a property of an inline resource to itself.
(User will expect "x x" to grab the parent property.)
Diffstat (limited to 'lib/chef/property.rb')
-rw-r--r--lib/chef/property.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 3c40c020b6..9aaa49c313 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -292,6 +292,16 @@ class Chef
value
else
+ # If we are still compiling this resource (rather than running an action
+ # on it), reading this property before it's been set is likely the wrong
+ # thing. Warn if it's a duplicate of the enclosing provider.
+ if resource.respond_to?(:enclosing_provider) && resource.enclosing_provider &&
+ !resource.currently_running_action &&
+ !name_property? &&
+ resource.enclosing_provider.respond_to?(name)
+ Chef::Log.warn("#{Chef::Log.caller_location}: property #{name} is declared in both #{resource} and #{resource.enclosing_provider}. Use new_resource.#{name} instead. At #{Chef::Log.caller_location}")
+ end
+
if has_default?
value = default
if value.is_a?(DelayedEvaluator)