From bb20bdaace0914a42857601825f97527db060a7f Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Thu, 3 Jun 2021 10:18:53 +0200 Subject: [PATCH] Catch exception raised when parsing It seems Clang can arbitrarily raise errors (transient NULL-byte reads from files that exist). Handle those errors by retrying the parsing step 3 times, just in case it goes away. --- lib/docurium/docparser.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/docurium/docparser.rb b/lib/docurium/docparser.rb index 29edf05cb..0190acb8b 100644 --- a/lib/docurium/docparser.rb +++ b/lib/docurium/docparser.rb @@ -70,7 +70,18 @@ def parse_file(orig_filename, opts = {}) args = includes.map { |path| "-I#{path}" } args << '-ferror-limit=1' - tu = Index.new(true, true).parse_translation_unit(filename, args, @unsaved, {:detailed_preprocessing_record => 1}) + attempts = 1 + begin + tu = Index.new(true, true).parse_translation_unit(filename, args, @unsaved, {:detailed_preprocessing_record => 1}) + rescue Exception => e + attempts += 1 + if attempts <= 3 + debug "parsing failed: #{e.inspect}, retrying..." + retry + end + puts "Exception raised while parsing #{filename}: #{e.inspect}" + return [] + end recs = []