mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/error_highlight] Make ErrorHighlight.spot accept Exception (https://github.com/ruby/error_highlight/pull/25)
... and move things from core_ext.rb to base.rb.
This will confine CRuby-dependent things to ErrorHighlight.spot.
22d1dd7824
This commit is contained in:
parent
1139bc8c20
commit
99e7fa5b37
3 changed files with 55 additions and 38 deletions
|
@ -3,36 +3,9 @@ require_relative "formatter"
|
|||
module ErrorHighlight
|
||||
module CoreExt
|
||||
private def generate_snippet
|
||||
locs = backtrace_locations
|
||||
return "" unless locs
|
||||
|
||||
loc = locs.first
|
||||
return "" unless loc
|
||||
|
||||
begin
|
||||
node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
|
||||
opts = {}
|
||||
|
||||
case self
|
||||
when NoMethodError, NameError
|
||||
opts[:point_type] = :name
|
||||
opts[:name] = name
|
||||
when TypeError, ArgumentError
|
||||
opts[:point_type] = :args
|
||||
end
|
||||
|
||||
spot = ErrorHighlight.spot(node, **opts)
|
||||
|
||||
rescue SyntaxError
|
||||
rescue SystemCallError # file not found or something
|
||||
rescue ArgumentError # eval'ed code
|
||||
end
|
||||
|
||||
if spot
|
||||
return ErrorHighlight.formatter.message_for(spot)
|
||||
end
|
||||
|
||||
""
|
||||
spot = ErrorHighlight.spot(self)
|
||||
return "" unless spot
|
||||
return ErrorHighlight.formatter.message_for(spot)
|
||||
end
|
||||
|
||||
if Exception.method_defined?(:detailed_message)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue