skryukov / rubocop-gradual

Gradually improve your code with RuboCop
MIT License
36 stars 0 forks source link

Crash during rake rubocop_gradual #12

Closed pboling closed 11 months ago

pboling commented 11 months ago

Firstly, I need to say: I love this gem - the idea is brilliant, and I'd love to help however I can!

I hacked the gem source to see what was going on:

   59:           str.each_byte.inject(5381) do |hash, b|
   60:             ((hash << 5) + hash) ^ b
   61:           end & 0xFFFFFFFF
   62:         rescue NoMethodError => error
   63:           byebug
   64:         end

Before hitting my byebug, I got this output:

❯ bundle exec rake rubocop_gradual
Running RuboCop Gradual...
................................
Found 13 files with 233 issue(s).
Processing results...
Return value is: nil

I am not familiar with that last line, having run rubocop_gradual many times now.

Here's some introspection after hitting my byebug:

(byebug) str
nil
(byebug) error.class
NoMethodError
(byebug) error.message
"undefined method `each_byte' for nil:NilClass"
(byebug) puts error.backtrace
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:59:in `djb2a'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:38:in `issue_hash'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:32:in `block in prepare_issues'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:32:in `map'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:32:in `prepare_issues'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:15:in `initialize'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results.rb:14:in `new'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results.rb:14:in `block in initialize'

I am not sure which file it is dying on... because str is nil... πŸ˜†

pboling commented 11 months ago

Note: The same issue occurs when running the executable instead of the rake task, so that's not relevant.

I replaced the byebug with a puts:

        rescue NoMethodError => error
          puts "skipping nil str"
          # byebug
        end

And then I got this:

Inspecting 32 file(s) for autocorrection...
................................
Fixed 0 file(s).
................................
Found 3 files with 40 issue(s).
Processing results...
skipping nil str
RuboCop Gradual got results for the first time. 40 issue(s) found.
Don't forget to commit `.rubocop_gradual.lock` log file.

So it clearly only failed the one time.

Here is the repo with the repro (link to GH Actions that failed - the error isn't very helpful, hence my local byebug)

skryukov commented 11 months ago

Hey, @pboling thanks for kind words!

Actually the fix was already in master πŸ˜… I just released a new version of the gem (0.3.2), so you can update your version and update/regenerate your lock file since this line lacks the hash value

pboling commented 11 months ago

Wonderful!