Skip to content

Commit 8504c52

Browse files
authored
Merge pull request #41 from ruby/rescue-runtime-error
Rescue runtime error for prism
2 parents 2fd2a1b + ac4101e commit 8504c52

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/error_highlight/base.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ def self.spot(obj, **opts)
5454

5555
return nil unless Thread::Backtrace::Location === loc
5656

57-
node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
57+
node =
58+
begin
59+
RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
60+
rescue RuntimeError => error
61+
# RubyVM::AbstractSyntaxTree.of raises an error with a message that
62+
# includes "prism" when the ISEQ was compiled with the prism compiler.
63+
# In this case, we'll set the node to `nil`. In the future, we will
64+
# reparse with the prism parser and pass the parsed node to Spotter.
65+
raise unless error.message.include?("prism")
66+
end
5867

5968
Spotter.new(node, **opts).spot
6069

0 commit comments

Comments
 (0)