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:, tool_name: nil) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
Constructor Details
#initialize(log_file:, exception_reporter:, tool_name: nil) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
7 8 9 10 11 |
# File 'lib/cli/kit/error_handler.rb', line 7 def initialize(log_file:, exception_reporter:, tool_name: nil) @log_file = log_file @exception_reporter_or_proc = exception_reporter || NullExceptionReporter @tool_name = tool_name end |
Instance Attribute Details
#exception=(value) ⇒ Object (writeonly)
maybe we can get rid of this.
36 37 38 |
# File 'lib/cli/kit/error_handler.rb', line 36 def exception=(value) @exception = value end |
Instance Method Details
#call(&block) ⇒ Object
19 20 21 22 |
# File 'lib/cli/kit/error_handler.rb', line 19 def call(&block) install! handle_abort(&block) end |
#handle_exception(error) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cli/kit/error_handler.rb', line 24 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 |