Skip to content

Commit

Permalink
Catch exception raised when parsing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tiennou committed Jun 3, 2021
1 parent a92cbf8 commit d464de3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/docurium/docparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down

0 comments on commit d464de3

Please sign in to comment.