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

Crash on empty else #3382

Closed
jcoyne opened this issue Aug 8, 2016 · 3 comments
Closed

Crash on empty else #3382

jcoyne opened this issue Aug 8, 2016 · 3 comments

Comments

@jcoyne
Copy link

jcoyne commented Aug 8, 2016

On this code: lawrencewoodman/mida@988cbe1

I ran rubocop -a and it makes a few changes, and then crashes.


Expected behavior

It runs all the autocorrects.

Actual behavior

Crash:

undefined method `begin_pos' for nil:NilClass
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/empty_else.rb:117:in `block in autocorrect'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/corrector.rb:57:in `block (2 levels) in rewrite'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/parser-2.3.1.2/lib/parser/source/rewriter.rb:194:in `transaction'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/corrector.rb:56:in `block in rewrite'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/corrector.rb:54:in `each'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/corrector.rb:54:in `rewrite'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:145:in `autocorrect_all_cops'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:77:in `autocorrect'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:105:in `block in offenses'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:122:in `investigate'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:101:in `offenses'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:52:in `inspect_file'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:223:in `inspect_file'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:193:in `block in do_inspection_loop'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:183:in `loop'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:183:in `do_inspection_loop'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:93:in `block in file_offenses'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:103:in `file_offense_cache'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:91:in `file_offenses'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:82:in `process_file'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:59:in `block in inspect_files'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:57:in `each'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:57:in `inspect_files'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:35:in `run'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cli.rb:72:in `execute_runner'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cli.rb:28:in `run'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/bin/rubocop:14:in `block in <top (required)>'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
/Users/jcoyne/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.42.0/bin/rubocop:13:in `<top (required)>'
/Users/jcoyne/.rbenv/versions/2.3.0/bin/rubocop:23:in `load'
/Users/jcoyne/.rbenv/versions/2.3.0/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.

RuboCop version

Include the output of rubocop -V:

$ rubocop -V
0.42.0 (using Parser 2.3.1.2, running on ruby 2.3.0 x86_64-darwin14)
@Drenmi
Copy link
Collaborator

Drenmi commented Aug 8, 2016

@jcoyne: Please try to highlight the code that causes this error. The only else-statement I can find in the code you provided doesn't have any offenses. 😀

@jcoyne
Copy link
Author

jcoyne commented Aug 8, 2016

@Drenmi I have no idea if there's anything in my code that's causing this.

@jcoyne
Copy link
Author

jcoyne commented Aug 8, 2016

@Drenmi according to the backtrace it's because this cop expects node.parent.loc.end to return something other than nil.

lumeet added a commit to lumeet/rubocop that referenced this issue Oct 4, 2016
An `if-elsif-else` expression containing multiple elsifs does not crash
when auto-correcting.
@bbatsov bbatsov closed this as completed in 9ea830e Oct 4, 2016
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
An `if-elsif-else` expression containing multiple elsifs does not crash
when auto-correcting.
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