From ac4101edaed5ecef1cafd02251c8de504e73f17c Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 14 Feb 2024 17:02:06 -0500 Subject: [PATCH] Rescue runtime error for prism --- lib/error_highlight/base.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/error_highlight/base.rb b/lib/error_highlight/base.rb index 7d2ff0c..b9c68b8 100644 --- a/lib/error_highlight/base.rb +++ b/lib/error_highlight/base.rb @@ -54,7 +54,16 @@ def self.spot(obj, **opts) return nil unless Thread::Backtrace::Location === loc - node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true) + node = + begin + RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true) + rescue RuntimeError => error + # RubyVM::AbstractSyntaxTree.of raises an error with a message that + # includes "prism" when the ISEQ was compiled with the prism compiler. + # In this case, we'll set the node to `nil`. In the future, we will + # reparse with the prism parser and pass the parsed node to Spotter. + raise unless error.message.include?("prism") + end Spotter.new(node, **opts).spot