summaryrefslogtreecommitdiff
path: root/lib/error_highlight/core_ext.rb
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2022-08-10 18:36:59 +0900
committergit <svn-admin@ruby-lang.org>2022-08-10 18:37:13 +0900
commit99e7fa5b3718d61d61427c67d244ec50b9eb8578 (patch)
tree34e74d18354ac62cbcd44bbdd29d791c2693e083 /lib/error_highlight/core_ext.rb
parent1139bc8c20d243b17f159d6c6518df17fcf887fe (diff)
[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. https://github.com/ruby/error_highlight/commit/22d1dd7824
Diffstat (limited to 'lib/error_highlight/core_ext.rb')
-rw-r--r--lib/error_highlight/core_ext.rb33
1 files changed, 3 insertions, 30 deletions
diff --git a/lib/error_highlight/core_ext.rb b/lib/error_highlight/core_ext.rb
index 53e409dd8f..130f9ef832 100644
--- a/lib/error_highlight/core_ext.rb
+++ b/lib/error_highlight/core_ext.rb
@@ -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)