Module: Girb::ExceptionCapture
- Defined in:
- lib/girb/exception_capture.rb
Class Attribute Summary collapse
-
.last_exception ⇒ Object
readonly
Returns the value of attribute last_exception.
-
.last_exception_binding ⇒ Object
readonly
Returns the value of attribute last_exception_binding.
Class Method Summary collapse
Class Attribute Details
.last_exception ⇒ Object (readonly)
Returns the value of attribute last_exception.
10 11 12 |
# File 'lib/girb/exception_capture.rb', line 10 def last_exception @last_exception end |
.last_exception_binding ⇒ Object (readonly)
Returns the value of attribute last_exception_binding.
10 11 12 |
# File 'lib/girb/exception_capture.rb', line 10 def last_exception_binding @last_exception_binding end |
Class Method Details
.capture(exception, binding = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/girb/exception_capture.rb', line 12 def capture(exception, binding = nil) @last_exception = { class: exception.class.name, message: exception., backtrace: exception.backtrace&.first(10), time: Time.now } @last_exception_binding = binding end |
.clear ⇒ Object
22 23 24 25 |
# File 'lib/girb/exception_capture.rb', line 22 def clear @last_exception = nil @last_exception_binding = nil end |
.install ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/girb/exception_capture.rb', line 27 def install return if @trace_point @trace_point = TracePoint.new(:raise) do |tp| # IRB内部・Ruby内部の例外は除外 next if tp.path&.include?("irb") next if tp.path&.include?("error_highlight") next if tp.path&.include?("reline") next if tp.path&.include?("readline") next if tp.path&.include?("rdoc") next if tp.path&.include?("/ri/") # forwardableは内部でSyntaxErrorを意図的に発生させてrescueする next if tp.path&.include?("forwardable") # rubygemsのrequireは最初にLoadErrorを発生させてからgemをアクティベートする next if tp.path&.include?("rubygems") next if tp.raised_exception.is_a?(SystemExit) next if tp.raised_exception.is_a?(Interrupt) # ErrorHighlight内部の例外を除外 next if tp.raised_exception.class.name&.start_with?("ErrorHighlight::") capture(tp.raised_exception, tp.binding) end @trace_point.enable end |
.uninstall ⇒ Object
52 53 54 55 |
# File 'lib/girb/exception_capture.rb', line 52 def uninstall @trace_point&.disable @trace_point = nil end |