def fix_resource_reference(resource_collection)
matching_resource = resource_collection.find(resource)
if Array(matching_resource).size > 1
msg = "Notification #{self} from #{notifying_resource} was created with a reference to multiple resources, "\
"but can only notify one resource. Notifying resource was defined on #{notifying_resource.source_line}"
raise Chef::Exceptions::InvalidResourceReference, msg
end
self.resource = matching_resource
rescue Chef::Exceptions::ResourceNotFound => e
err = Chef::Exceptions::ResourceNotFound.new("resource \#{notifying_resource} is configured to notify resource \#{resource} with action \#{action}, \\\nbut \#{resource} cannot be found in the resource collection. \#{notifying_resource} is defined in \\\n\#{notifying_resource.source_line}\n")
err.set_backtrace(e.backtrace)
raise err
rescue Chef::Exceptions::InvalidResourceSpecification => e
err = Chef::Exceptions::InvalidResourceSpecification.new("Resource \#{notifying_resource} is configured to notify resource \#{resource} with action \#{action}, \\\nbut \#{resource.inspect} is not valid syntax to look up a resource in the resource collection. Notification \\\nis defined near \#{notifying_resource.source_line}\n")
err.set_backtrace(e.backtrace)
raise err
end