Skip to content

Commit 6715ad1

Browse files
committed
Catch RuntimeError when parsing
RubyParser raises `RuntimeError` instead of anything more specific in certain parse error contexts. This presents a challenge for catching these, since many error types (including `Timeout::Error`, which we don't want to catch) inherit from `RuntimeError`. So I've had to shift from two `rescue` clauses to one `rescue` clause that uses internal logic to decide if the error should be re-raised.
1 parent 21899c6 commit 6715ad1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/cc/engine/analyzers/analyzer_base.rb

+8-5
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ class Base
99
::Errno::ENOENT,
1010
::Racc::ParseError,
1111
::RubyParser::SyntaxError,
12-
]
12+
::RuntimeError,
13+
].freeze
1314

1415
def initialize(engine_config:)
1516
@engine_config = engine_config
1617
end
1718

1819
def run(file)
1920
process_file(file)
20-
rescue *RESCUABLE_ERRORS => ex
21-
$stderr.puts("Skipping file #{file} due to exception (#{ex.class}): #{ex.message}\n#{ex.backtrace.join("\n")}")
2221
rescue => ex
23-
$stderr.puts("#{ex.class} error occurred processing file #{file}: aborting.")
24-
raise ex
22+
if RESCUABLE_ERRORS.map { |klass| ex.instance_of?(klass) }.include?(true)
23+
$stderr.puts("Skipping file #{file} due to exception (#{ex.class}): #{ex.message}\n#{ex.backtrace.join("\n")}")
24+
else
25+
$stderr.puts("#{ex.class} error occurred processing file #{file}: aborting.")
26+
raise ex
27+
end
2528
end
2629

2730
def files

0 commit comments

Comments
 (0)