From 174f7c6767b31ed47b01c6e195f7b6274cf36717 Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Tue, 10 Nov 2026 15:31:54 -0400 Subject: [PATCH] fix: keep notifying remaining listeners when one raises send_notifications returned from the loop after logging a failing callback, so every listener registered after it was skipped. Log the error and continue; the method still returns nil. --- lib/optimizely/notification_center.rb | 3 ++- spec/notification_center_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/optimizely/notification_center.rb b/lib/optimizely/notification_center.rb index e4054595..9e2be657 100644 --- a/lib/optimizely/notification_center.rb +++ b/lib/optimizely/notification_center.rb @@ -140,8 +140,9 @@ def send_notifications(notification_type, *args) @logger.log Logger::INFO, "Notification #{notification_type} sent successfully." rescue => e @logger.log(Logger::ERROR, "Problem calling notify callback. Error: #{e}") - return nil end + + nil end def notification_count(notification_type) diff --git a/spec/notification_center_spec.rb b/spec/notification_center_spec.rb index 7ac4e808..b7bbe7d5 100644 --- a/spec/notification_center_spec.rb +++ b/spec/notification_center_spec.rb @@ -479,6 +479,19 @@ def deliver_three; end .with(Logger::INFO, 'delivered two.') end + it 'should keep calling remaining listeners when an earlier listener raises' do + notification_type = Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE] + failing = ->(_args) { raise 'listener failure' } + notification_center.add_notification_listener(notification_type, failing) + notification_center.add_notification_listener(notification_type, invitation.method(:deliver_two)) + + expect { notification_center.send_notifications(notification_type, @args) }.to_not raise_error + expect(spy_logger).to have_received(:log) + .with(Logger::ERROR, 'Problem calling notify callback. Error: listener failure') + expect(spy_logger).to have_received(:log).once + .with(Logger::INFO, 'delivered two.') + end + it 'should send notifications and verify that all callbacks are called' do notification_type_decision = Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE] notification_type_track = Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK]