Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi instruction lines (with semicolons) cause "Cannot get the first element of beginless range (RangeError)" #1326

Closed
svl7 opened this issue Apr 22, 2020 · 1 comment

Comments

@svl7
Copy link

svl7 commented Apr 22, 2020

On parsing our repo, yardoc fails with cannot get the first element of beginless range (RangeError).
The --debug option tells the name of the file that got parsed when the error occured.
While trying to narrow down the source of the error, I noticed that for example a line that includes multiple instructions on a single line (separated with a semicolon) seems to cause this issue.

There might be other ways to cause this issue, but so far I identified several files where it fails at lines with multiple instructions.

Steps to reproduce

  1. Add the line puts "#{if var; 'yes'; else 'nope'; end}" to a ruby file
  2. Run the following command: yardoc <filename.rb>

Actual Output

[debug]: Parsing path/to/file.rb
Traceback (most recent call last):
        28: from /home/vagrant/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
        27: from /home/vagrant/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
        26: from /home/vagrant/.rvm/gems/ruby-2.7.0/bin/yard:23:in `<main>'
        25: from /home/vagrant/.rvm/gems/ruby-2.7.0/bin/yard:23:in `load'
        24: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/bin/yard:13:in `<top (required)>'
        23: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/cli/command_parser.rb:54:in `run'
        22: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/cli/command_parser.rb:72:in `run'
        21: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/cli/command.rb:14:in `run'
        20: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/cli/yardoc.rb:258:in `run'
        19: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/registry.rb:210:in `lock_for_writing'
        18: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/registry_store.rb:202:in `lock_for_writing'
        17: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/serializers/yardoc_serializer.rb:56:in `lock_for_writing'
        16: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/cli/yardoc.rb:259:in `block in run'
        15: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard.rb:20:in `parse'
        14: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/source_parser.rb:113:in `parse'
        13: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/logging.rb:182:in `enter_level'
        12: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/source_parser.rb:114:in `block in parse'
        11: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/source_parser.rb:371:in `parse_in_order'
        10: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/source_parser.rb:45:in `parse'
         9: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/logging.rb:82:in `capture'
         8: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/source_parser.rb:46:in `block in parse'
         7: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/source_parser.rb:442:in `parse'
         6: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/ruby/ruby_parser.rb:17:in `parse'
         5: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/ruby/ruby_parser.rb:60:in `parse'
         4: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/ruby/ruby_parser.rb:614:in `insert_comments'
         3: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/ruby/ast_node.rb:212:in `traverse'
         2: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/ruby/ruby_parser.rb:623:in `block in insert_comments'
         1: from /home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/ruby/ast_node.rb:274:in `line'
/home/vagrant/.rvm/gems/ruby-2.7.0/gems/yard-0.9.24/lib/yard/parser/ruby/ast_node.rb:274:in `first': cannot get the first element of beginless range (RangeError)

Expected Output

Ruby file gets parsed and documentation created.

Environment details:

  • OS: Ubuntu 18.04
  • Ruby version (ruby -v): ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
  • YARD version (yard -v): yard 0.9.24

I have read the Contributing Guide.

lsegal added a commit that referenced this issue May 3, 2020
Resolves "beginless range" error.

Fixes #1308, #1324, #1326, #1327
@lsegal
Copy link
Owner

lsegal commented May 3, 2020

Fixed in e3e8321

@lsegal lsegal closed this as completed May 3, 2020
lsegal added a commit that referenced this issue May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants