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

undefined method `empty?' for nil:NilClass in progress_formatter.rb #1642

Closed
DavidEGrayson opened this issue Feb 7, 2015 · 6 comments
Closed

Comments

@DavidEGrayson
Copy link

There seems to be a bug in Rubocop 0.29.0. I am running it on Arch Linux 64-bit with Ruby 2.2.0.

To reproduce the bug, I made a new directory that just contains a .rubocop.yml file with the following contents:

AllCops:
  Exclude:
    - **/*_old.rb

Then I ran rubocop (with no options) at the command line and it produced the following output:

undefined method `empty?' for nil:NilClass
/home/david/.gem/ruby/2.2.0/gems/rubocop-0.29.0/lib/rubocop/formatter/progress_formatter.rb:28:in `finished'
/home/david/.gem/ruby/2.2.0/gems/rubocop-0.29.0/lib/rubocop/formatter/formatter_set.rb:28:in `block (3 levels) in <class:FormatterSet>'
/home/david/.gem/ruby/2.2.0/gems/rubocop-0.29.0/lib/rubocop/formatter/formatter_set.rb:28:in `each'
/home/david/.gem/ruby/2.2.0/gems/rubocop-0.29.0/lib/rubocop/formatter/formatter_set.rb:28:in `block (2 levels) in <class:FormatterSet>'
/home/david/.gem/ruby/2.2.0/gems/rubocop-0.29.0/lib/rubocop/runner.rb:46:in `ensure in run'
/home/david/.gem/ruby/2.2.0/gems/rubocop-0.29.0/lib/rubocop/runner.rb:47:in `run'
/home/david/.gem/ruby/2.2.0/gems/rubocop-0.29.0/lib/rubocop/cli.rb:24:in `run'
/home/david/.gem/ruby/2.2.0/gems/rubocop-0.29.0/bin/rubocop:13:in `block in <top (required)>'
/opt/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
/home/david/.gem/ruby/2.2.0/gems/rubocop-0.29.0/bin/rubocop:12:in `<top (required)>'
/home/david/.gem/ruby/2.2.0/bin/rubocop:23:in `load'
/home/david/.gem/ruby/2.2.0/bin/rubocop:23:in `<main>'
@askreet
Copy link

askreet commented Feb 7, 2015

I see this behavior with master on OS X, Ruby 2.1.5.

Running with 0.27.1 (which I happen to have installed), I see a different error:

(<unknown>): did not find expected alphabetic or numeric character while scanning an alias at line 3 column 7
/Users/kyle.smith/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:370:in `parse'
/Users/kyle.smith/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:370:in `parse_stream'
/Users/kyle.smith/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:318:in `parse'
/Users/kyle.smith/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:245:in `load'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/lib/rubocop/config_loader.rb:34:in `load_file'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/lib/rubocop/config_loader.rb:93:in `configuration_from_file'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/lib/rubocop/config_store.rb:40:in `for'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/lib/rubocop/target_finder.rb:62:in `target_files_in_dir'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/lib/rubocop/target_finder.rb:31:in `find'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/lib/rubocop/runner.rb:47:in `find_target_files'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/lib/rubocop/runner.rb:18:in `run'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/lib/rubocop/cli.rb:24:in `run'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/bin/rubocop:13:in `block in <top (required)>'
/Users/kyle.smith/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/gems/rubocop-0.27.1/bin/rubocop:12:in `<top (required)>'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/bin/rubocop:23:in `load'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/bin/rubocop:23:in `<main>'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
/Users/kyle.smith/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'

It seems as though you have to quote a string like **/*_old.rb in YAML, though the error could be more helpful as it used to be.

@bquorning
Copy link
Contributor

It took some digging around, but I think I found it: The ensure call added in ece834e doesn’t allow the Psych::SyntaxError raised by YAML.load in https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/config_loader.rb#L117 to walk all the way up to https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cli.rb#L32-L35 as it previously did.

cc @jonas054

@bquorning
Copy link
Contributor

And yes, the SyntaxError exception is caused by **/*_old.rb not being quoted. This config file should word:

AllCops:
  Exclude:
    - "**/*_old.rb"

@jonas054
Copy link
Collaborator

jonas054 commented Feb 8, 2015

@bquorning Exactly. We get a second exception inside the ensure block, which is why the original exception is lost. This could be solved by adding a begin and end inside Runner#run. The only problem is that we'll overstep the MethodLength by doing so.

I don't have time to fix this myself, going on vacation tomorrow, so I'd be grateful if someone could submit a PR.

@bquorning
Copy link
Contributor

@jonas054 There’s a PR here: #1643.

@jonas054
Copy link
Collaborator

jonas054 commented Feb 8, 2015

@bquorning Nice! I see that you and @bbatsov are working out the details. Looks good!

@bbatsov bbatsov closed this as completed in ccce095 Feb 9, 2015
bbatsov added a commit that referenced this issue Feb 9, 2015
[Fix #1642] Raise right exception on bad config
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

4 participants