I have a chef resource and I just added linting with cookstyle to the cookbook. I have this line in the cookbook:
existing_value = key.to_s.split('.').inject(node.elasticsearch) { |result, attr| result[attr] } rescue nil if existing_value.nil?
It's causing the linter to error. I tried a couple of things, but I'm not sure how to say the same thing and pass the lint test.
Style/RescueModifier: Avoid using rescue in its modifier form
If I remove the rescue statement entirely, it causes this exception:
Chef::Mixin::Template::TemplateError (undefined method `[]' for nil:NilClass) on line #52:
...
52: <%= print_value 'action.destructive_requires_name' -%>
...