Class: CLI::Kit::ErrorHandler
- Inherits:
-
Object
- Object
- CLI::Kit::ErrorHandler
- Extended by:
- T::Sig
- Defined in:
- lib/cli/kit/error_handler.rb
Defined Under Namespace
Classes: ExceptionReporter, NullExceptionReporter
Constant Summary collapse
- ExceptionReporterOrProc =
T.type_alias do T.any(T.class_of(ExceptionReporter), T.proc.returns(T.class_of(ExceptionReporter))) end
- SIGNALS_THAT_ARENT_BUGS =
[ 'SIGTERM', 'SIGHUP', 'SIGINT', ].freeze
Instance Attribute Summary collapse
-
#override_exception_handler ⇒ Object
writeonly
Sets the attribute override_exception_handler.
Instance Method Summary collapse
- #call(&block) ⇒ Object
-
#initialize(log_file: nil, exception_reporter: NullExceptionReporter, tool_name: nil, dev_mode: false) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
- #report_exception(error) ⇒ Object
Methods included from T::Sig
Constructor Details
#initialize(log_file: nil, exception_reporter: NullExceptionReporter, tool_name: nil, dev_mode: false) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
26 27 28 29 30 31 |
# File 'lib/cli/kit/error_handler.rb', line 26 def initialize(log_file: nil, exception_reporter: NullExceptionReporter, tool_name: nil, dev_mode: false) @log_file = log_file @exception_reporter_or_proc = exception_reporter @tool_name = tool_name @dev_mode = dev_mode end |
Instance Attribute Details
#override_exception_handler=(value) ⇒ Object (writeonly)
Sets the attribute override_exception_handler
16 17 18 |
# File 'lib/cli/kit/error_handler.rb', line 16 def override_exception_handler=(value) @override_exception_handler = value end |
Instance Method Details
#call(&block) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/cli/kit/error_handler.rb', line 60 def call(&block) # @at_exit_exception is set if handle_abort decides to submit an error. # $ERROR_INFO is set if we terminate because of a signal. at_exit { report_exception(@at_exit_exception || $ERROR_INFO) } triage_all_exceptions(&block) end |
#report_exception(error) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cli/kit/error_handler.rb', line 68 def report_exception(error) if (notify_with = exception_for_submission(error)) logs = nil if @log_file logs = begin File.read(@log_file) rescue => e "(#{e.class}: #{e.})" end end exception_reporter.report(notify_with, logs) end end |