Module: ErrorReporting

Included in:
MarkdownExec::HashDelegator, MarkdownExec::SearchResultsReport
Defined in:
lib/error_reporting.rb

Overview

Module providing standardized error‐reporting: logs either an Exception’s details or a simple string message—optionally with context—and then re‐raises either the original Exception or a new RuntimeError for string messages.

Including this module gives you:

• instance method  → report_and_reraise(...)
• class method     → report_and_reraise(...)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



16
17
18
# File 'lib/error_reporting.rb', line 16

def self.included(base)
  base.extend(self)
end

Instance Method Details

#report_and_reraise(error_or_message, context: nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/error_reporting.rb', line 20

def report_and_reraise(error_or_message, context: nil)
  if error_or_message.is_a?(Exception)
    header = +"#{error_or_message.class}: #{error_or_message.message}"
    header << " (#{context})" if context

    ww header
    ww error_or_message.backtrace.join("\n") if error_or_message.backtrace

    raise error_or_message
  else
    header = +error_or_message.to_s
    header << " (#{context})" if context

    ww header

    raise error_or_message.to_s
  end
end