Module: Pgbus::ErrorReporter
- Defined in:
- lib/pgbus/error_reporter.rb
Overview
Central error reporting module. Iterates all configured error reporters and logs the error. Inspired by Sidekiq’s error_handlers pattern.
Usage:
Pgbus::ErrorReporter.report(exception, { queue: "default" })
Configuration:
Pgbus.configure do |c|
c.error_reporters << ->(ex, ctx) { Appsignal.set_error(ex) { |t| t.(ctx) } }
end
Class Method Summary collapse
- .call_handler(handler, exception, context, config) ⇒ Object
- .log_error(exception, context, config:) ⇒ Object
- .report(exception, context = {}, config: Pgbus.configuration) ⇒ Object
Class Method Details
.call_handler(handler, exception, context, config) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/pgbus/error_reporter.rb', line 31 def call_handler(handler, exception, context, config) target = handler.is_a?(Proc) ? handler : handler.method(:call) if target.arity == 3 || (target.arity.negative? && target.parameters.size >= 3) handler.call(exception, context, config) else handler.call(exception, context) end end |
.log_error(exception, context, config:) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/pgbus/error_reporter.rb', line 40 def log_error(exception, context, config:) config.logger.error do msg = "[Pgbus] #{exception.class}: #{exception.}" msg += " (#{context.inspect})" unless context.empty? msg end end |
.report(exception, context = {}, config: Pgbus.configuration) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pgbus/error_reporter.rb', line 17 def report(exception, context = {}, config: Pgbus.configuration) log_error(exception, context, config: config) config.error_reporters.each do |handler| call_handler(handler, exception, context, config) rescue Exception => e # rubocop:disable Lint/RescueException config.logger.error { "[Pgbus] Error reporter raised: #{e.class}: #{e.}" } end rescue Exception # rubocop:disable Lint/RescueException # ErrorReporter must never raise — callers sit inside rescue blocks # where an unexpected raise would break fault-tolerance invariants. nil end |