Module: Aidp::RescueLogging

Overview

Mixin providing a unified helper for logging rescued exceptions. Usage:

include Aidp::RescueLogging
rescue => e
  log_rescue(e, component: "storage", action: "store file", fallback: {success: false})

Defaults:

- level: :warn (so filtering WARN surfaces rescue sites)
- includes error class, message
- optional fallback and extra context hash merged in

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__log_rescue_impl(context_object, error, component:, action:, fallback:, level:, **extra) ⇒ Object

Internal implementation shared by instance & module forms



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/aidp/rescue_logging.rb', line 27

def self.__log_rescue_impl(context_object, error, component:, action:, fallback:, level:, **extra)
  data = {
    error_class: error.class.name,
    error_message: error.message,
    action: action
  }
  data[:fallback] = fallback if fallback
  data.merge!(extra) unless extra.empty?

  begin
    if context_object.respond_to?(:debug_log)
      context_object.debug_log("⚠️ Rescue in #{component}: #{action}", level: level, data: data)
    else
      Aidp.logger.send(level, component, "Rescued exception during #{action}", **data)
    end
  rescue => logging_error
    warn "[AIDP Rescue Logging Error] Failed to log rescue for #{component}:#{action} - #{error.class}: #{error.message} (logging error: #{logging_error.message})"
  end
end

.log_rescue(error, component:, action:, fallback: nil, level: :warn, **context) ⇒ Object

Module-level access (Aidp::RescueLogging.log_rescue) for direct calls if desired



22
23
24
# File 'lib/aidp/rescue_logging.rb', line 22

def self.log_rescue(error, component:, action:, fallback: nil, level: :warn, **context)
  Aidp::RescueLogging.__log_rescue_impl(self, error, component: component, action: action, fallback: fallback, level: level, **context)
end

Instance Method Details

#log_rescue(error, component:, action:, fallback: nil, level: :warn, **context) ⇒ Object

Instance-level helper (made public so extend works for singleton contexts)



17
18
19
# File 'lib/aidp/rescue_logging.rb', line 17

def log_rescue(error, component:, action:, fallback: nil, level: :warn, **context)
  Aidp::RescueLogging.__log_rescue_impl(self, error, component: component, action: action, fallback: fallback, level: level, **context)
end