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(, context: nil) if .is_a?(Exception) header = +"#{.class}: #{.}" header << " (#{context})" if context ww header ww .backtrace.join("\n") if .backtrace raise else header = +.to_s header << " (#{context})" if context ww header raise .to_s end end |