From 6715ad152d95c3533e2722b3fd6e716354fb3616 Mon Sep 17 00:00:00 2001 From: Will Fleming Date: Wed, 30 Dec 2015 11:43:38 -0500 Subject: [PATCH] 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. --- lib/cc/engine/analyzers/analyzer_base.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/cc/engine/analyzers/analyzer_base.rb b/lib/cc/engine/analyzers/analyzer_base.rb index 4ea23cfd..d9d689ed 100644 --- a/lib/cc/engine/analyzers/analyzer_base.rb +++ b/lib/cc/engine/analyzers/analyzer_base.rb @@ -9,7 +9,8 @@ class Base ::Errno::ENOENT, ::Racc::ParseError, ::RubyParser::SyntaxError, - ] + ::RuntimeError, + ].freeze def initialize(engine_config:) @engine_config = engine_config @@ -17,11 +18,13 @@ def initialize(engine_config:) def run(file) process_file(file) - rescue *RESCUABLE_ERRORS => ex - $stderr.puts("Skipping file #{file} due to exception (#{ex.class}): #{ex.message}\n#{ex.backtrace.join("\n")}") rescue => ex - $stderr.puts("#{ex.class} error occurred processing file #{file}: aborting.") - raise ex + if RESCUABLE_ERRORS.map { |klass| ex.instance_of?(klass) }.include?(true) + $stderr.puts("Skipping file #{file} due to exception (#{ex.class}): #{ex.message}\n#{ex.backtrace.join("\n")}") + else + $stderr.puts("#{ex.class} error occurred processing file #{file}: aborting.") + raise ex + end end def files