Class: CLI::Kit::ErrorHandler
- Inherits:
-
Object
- Object
- CLI::Kit::ErrorHandler
- Defined in:
- lib/cli/kit/error_handler.rb
Defined Under Namespace
Modules: NullExceptionReporter
Instance Attribute Summary collapse
-
#exception ⇒ Object
writeonly
maybe we can get rid of this.
Instance Method Summary collapse
- #call(&block) ⇒ Object
- #handle_exception(error) ⇒ Object
-
#initialize(log_file:, exception_reporter:) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
Constructor Details
#initialize(log_file:, exception_reporter:) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
7 8 9 10 |
# File 'lib/cli/kit/error_handler.rb', line 7 def initialize(log_file:, exception_reporter:) @log_file = log_file @exception_reporter_or_proc = exception_reporter || NullExceptionReporter end |
Instance Attribute Details
#exception=(value) ⇒ Object (writeonly)
maybe we can get rid of this.
35 36 37 |
# File 'lib/cli/kit/error_handler.rb', line 35 def exception=(value) @exception = value end |
Instance Method Details
#call(&block) ⇒ Object
18 19 20 21 |
# File 'lib/cli/kit/error_handler.rb', line 18 def call(&block) install! handle_abort(&block) end |
#handle_exception(error) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cli/kit/error_handler.rb', line 23 def handle_exception(error) if notify_with = exception_for_submission(error) logs = begin File.read(@log_file) rescue => e "(#{e.class}: #{e.})" end exception_reporter.report(notify_with, logs) end end |