Class: Findbug::Capture::ExceptionSubscriber
- Inherits:
-
Object
- Object
- Findbug::Capture::ExceptionSubscriber
- Defined in:
- lib/findbug/capture/exception_subscriber.rb
Overview
ExceptionSubscriber integrates with Rails 7’s ErrorReporter.
RAILS ERROR REPORTER (Rails 7+)
Rails 7 introduced a centralized error reporting API:
Rails.error.handle { risky_operation } # Swallows error, reports it
Rails.error.record { risky_operation } # Re-raises, but reports first
Third-party gems can subscribe to receive ALL reported errors:
Rails.error.subscribe(MySubscriber.new)
This is better than just middleware because it catches:
-
Errors handled gracefully with Rails.error.handle
-
Background job errors
-
Errors in non-request contexts
HOW IT WORKS
-
Rails catches an exception
-
Rails calls Rails.error.report(exception, …)
-
Rails calls our subscriber’s #report method
-
We capture the exception asynchronously
Instance Method Summary collapse
-
#report(error, handled:, severity:, context:, source: nil) ⇒ Object
Called by Rails when an error is reported.
Instance Method Details
#report(error, handled:, severity:, context:, source: nil) ⇒ Object
Called by Rails when an error is reported
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/findbug/capture/exception_subscriber.rb', line 41 def report(error, handled:, severity:, context:, source: nil) return unless Findbug.enabled? return unless should_capture?(error) # Build event data event_data = build_event_data(error, handled, severity, context, source) # Push to Redis buffer (async, non-blocking) Storage::RedisBuffer.push_error(event_data) rescue StandardError => e # CRITICAL: Never let Findbug crash your app Findbug.logger.error("[Findbug] ExceptionSubscriber failed: #{e.}") end |