lib/active_support/notifications/fanout.rb in activesupport-7.1.1 vs lib/active_support/notifications/fanout.rb in activesupport-7.1.2

- old
+ new

@@ -16,30 +16,34 @@ super "Exception(s) occurred within instrumentation subscribers: #{exception_class_names.join(', ')}" end end module FanoutIteration # :nodoc: - def iterate_guarding_exceptions(listeners) - exceptions = nil + private + def iterate_guarding_exceptions(collection) + exceptions = nil - listeners.each do |s| - yield s - rescue Exception => e - exceptions ||= [] - exceptions << e - end + collection.each do |s| + yield s + rescue Exception => e + exceptions ||= [] + exceptions << e + end - if exceptions - if exceptions.size == 1 - raise exceptions.first - else - raise InstrumentationSubscriberError.new(exceptions), cause: exceptions.first + if exceptions + exceptions = exceptions.flat_map do |exception| + exception.is_a?(InstrumentationSubscriberError) ? exception.exceptions : [exception] + end + if exceptions.size == 1 + raise exceptions.first + else + raise InstrumentationSubscriberError.new(exceptions), cause: exceptions.first + end end - end - listeners - end + collection + end end # This is a default queue implementation that ships with Notifications. # It just pushes events to all registered log subscribers. # @@ -223,10 +227,12 @@ # # work to be instrumented # ensure # handle.finish # end class Handle + include FanoutIteration + def initialize(notifier, name, id, payload) # :nodoc: @name = name @id = id @payload = payload @groups = notifier.groups_for(name).map do |group_klass, grouped_listeners| @@ -237,11 +243,11 @@ def start ensure_state! :initialized @state = :started - @groups.each do |group| + iterate_guarding_exceptions(@groups) do |group| group.start(@name, @id, @payload) end end def finish @@ -250,10 +256,10 @@ def finish_with_values(name, id, payload) # :nodoc: ensure_state! :started @state = :finished - @groups.each do |group| + iterate_guarding_exceptions(@groups) do |group| group.finish(name, id, payload) end end private