I have a wrapper cookbook which use custom resource
sensu_gem from cookbook chef-sensu. I want to catch its Exception but cannot.
The code is.
sensu_gem "pg" do
compile_time true if respond_to?(:compile_time)
rescue Exception => e
It worked fine with built-in Chef resource
That pattern generally won’t work. It happens to work for
chef_gem because you’re running it at compile time. If you just want to ignore the failure and keep going, there’s
ignore_failure true and if you want retries, there is a property for that. If you need custom logic based on the exception type or content, then you probably need to wrap the resource in another resource.