summaryrefslogtreecommitdiff
path: root/lib/chef/resource.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/resource.rb')
-rw-r--r--lib/chef/resource.rb25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 997c614171..7d96b26b4b 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -21,7 +21,9 @@ require 'chef/mixin/params_validate'
require 'chef/dsl/platform_introspection'
require 'chef/dsl/data_query'
require 'chef/dsl/registry_helper'
+require 'chef/dsl/reboot_pending'
require 'chef/mixin/convert_to_class_name'
+require 'chef//guard_interpreter/resource_guard_interpreter'
require 'chef/resource/conditional'
require 'chef/resource/conditional_action_not_nothing'
require 'chef/resource_collection'
@@ -125,6 +127,7 @@ F
include Chef::Mixin::ParamsValidate
include Chef::DSL::PlatformIntrospection
include Chef::DSL::RegistryHelper
+ include Chef::DSL::RebootPending
include Chef::Mixin::ConvertToClassName
include Chef::Mixin::Deprecation
@@ -247,6 +250,7 @@ F
@not_if = []
@only_if = []
@source_line = nil
+ @guard_interpreter = :default
@elapsed_time = 0
@node = run_context ? deprecated_ivar(run_context.node, :node, :warn) : nil
@@ -399,6 +403,14 @@ F
ignore_failure(arg)
end
+ def guard_interpreter(arg=nil)
+ set_or_return(
+ :guard_interpreter,
+ arg,
+ :kind_of => Symbol
+ )
+ end
+
# Sets up a notification from this resource to the resource specified by +resource_spec+.
def notifies(action, resource_spec, timing=:delayed)
# when using old-style resources(:template => "/foo.txt") style, you
@@ -550,7 +562,7 @@ F
# * evaluates to false if the block is false, or if the command returns a non-zero exit code.
def only_if(command=nil, opts={}, &block)
if command || block_given?
- @only_if << Conditional.only_if(command, opts, &block)
+ @only_if << Conditional.only_if(self, command, opts, &block)
end
@only_if
end
@@ -571,7 +583,7 @@ F
# * evaluates to false if the block is true, or if the command returns a 0 exit status.
def not_if(command=nil, opts={}, &block)
if command || block_given?
- @not_if << Conditional.not_if(command, opts, &block)
+ @not_if << Conditional.not_if(self, command, opts, &block)
end
@not_if
end
@@ -625,7 +637,7 @@ F
provider_for_action(action).run_action
rescue Exception => e
if ignore_failure
- Chef::Log.error("#{self} (#{defined_at}) had an error: #{e.message}; ignore_failure is set, continuing")
+ Chef::Log.error("#{custom_exception_message(e)}; ignore_failure is set, continuing")
events.resource_failed(self, action, e)
elsif retries > 0
events.resource_failed_retriable(self, action, retries, e)
@@ -660,8 +672,12 @@ F
end
end
+ def custom_exception_message(e)
+ "#{self} (#{defined_at}) had an error: #{e.class.name}: #{e.message}"
+ end
+
def customize_exception(e)
- new_exception = e.exception("#{self} (#{defined_at}) had an error: #{e.class.name}: #{e.message}")
+ new_exception = e.exception(custom_exception_message(e))
new_exception.set_backtrace(e.backtrace)
new_exception
end
@@ -813,6 +829,5 @@ F
end
end
end
-
end
end