Skip to content

Commit ea21b88

Browse files
castwideapiology
authored andcommitted
Rescue exceptions in docstring parsing (castwide#830)
1 parent a88188d commit ea21b88

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/solargraph/source.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ def parse_docstring comments
491491
# HACK: Pass a dummy code object to the parser for plugins that
492492
# expect it not to be nil
493493
YARD::Docstring.parser.parse(comments, YARD::CodeObjects::Base.new(:root, 'stub'))
494+
rescue StandardError => e
495+
Solargraph.logger.info "YARD failed to parse docstring: [#{e.class}] #{e.message}"
496+
Solargraph.logger.debug "Unparsed comment: #{comments}"
497+
YARD::Docstring.parser
494498
end
495499
end
496500
end

spec/source_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,10 @@ class Foo
317317
)
318318
expect(source.string_ranges.length).to eq(4)
319319
end
320+
321+
it 'handles errors in docstrings' do
322+
# YARD has a known problem with empty @overload tags
323+
comments = "@overload\n@return [String]"
324+
expect { Solargraph::Source.parse_docstring(comments) }.not_to raise_error
325+
end
320326
end

0 commit comments

Comments
 (0)