Module: ErrorRadar::Integrations::Rake::Capture

Defined in:
lib/error_radar/integrations/rake.rb

Overview

Prepended into Rake::Task to auto-capture exceptions raised inside any task body. Uses prepend (not alias_method) so it composes safely with any other patches already in place — including older versions of this integration that may be in the host app's lib/tasks/error_radar.rake.

Instance Method Summary collapse

Instance Method Details

#execute(args = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/error_radar/integrations/rake.rb', line 11

def execute(args = nil)
  super
rescue Exception => e # rubocop:disable Lint/RescueException
  # Never try to capture signals or stack overflows — we can't recover.
  raise if e.is_a?(SignalException) || e.is_a?(SystemStackError) || e.is_a?(NoMemoryError)

  # Thread-local guard: if capture itself fails and re-raises, we must
  # not enter an infinite rescue loop.
  unless Thread.current[:error_radar_rake_capturing]
    Thread.current[:error_radar_rake_capturing] = true
    begin
      ErrorRadar.capture(
        e,
        source:   "rake:#{name}",
        category: :background_job,
        context:  { task: name }
      )
    ensure
      Thread.current[:error_radar_rake_capturing] = false
    end
  end
  raise
end