oleander / git-fame-rb

A command-line tool that helps you summarize and pretty-print collaborators based on contributions
MIT License
948 stars 73 forks source link

Crash: tty-spinner terminates with exception #133

Closed tvincent2 closed 4 months ago

tvincent2 commented 5 months ago

Hi!

I just installed git-fame-rb using sudo gem install git_fame and tried to run it on a project. I get this crash:

$ git fame
[|] git-fame is crunching the numbers, hold on ...#<Thread:0x00007f25b4723ab8 /var/lib/gems/3.1.0/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308 run> terminated with exception (report_on_exception is true):
/var/lib/gems/3.1.0/gems/activesupport-7.1.3.2/lib/active_support/core_ext/enumerable.rb:218:in `block in compact_blank': undefined method `blank?' for "HEAD":String (NoMethodError)

    reject { |_k, v| v.blank? }
                      ^^^^^^^
    from /var/lib/gems/3.1.0/gems/activesupport-7.1.3.2/lib/active_support/core_ext/enumerable.rb:218:in `reject'
    from /var/lib/gems/3.1.0/gems/activesupport-7.1.3.2/lib/active_support/core_ext/enumerable.rb:218:in `compact_blank'
    from /var/lib/gems/3.1.0/gems/git_fame-3.1.1/lib/git_fame/command.rb:140:in `filter'
    from /var/lib/gems/3.1.0/gems/git_fame-3.1.1/lib/git_fame/command.rb:152:in `collector'
    from /var/lib/gems/3.1.0/gems/git_fame-3.1.1/lib/git_fame/command.rb:168:in `result'
    from /var/lib/gems/3.1.0/gems/git_fame-3.1.1/lib/git_fame/command.rb:127:in `block in run'
    from /var/lib/gems/3.1.0/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in `execute_job'
    from /var/lib/gems/3.1.0/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in `block in run'
[|] git-fame is crunching the numbers, hold on ...
/var/lib/gems/3.1.0/gems/activesupport-7.1.3.2/lib/active_support/core_ext/enumerable.rb:218:in `block in compact_blank': undefined method `blank?' for "HEAD":String (NoMethodError)

    reject { |_k, v| v.blank? }
                      ^^^^^^^
    from /var/lib/gems/3.1.0/gems/activesupport-7.1.3.2/lib/active_support/core_ext/enumerable.rb:218:in `reject'
    from /var/lib/gems/3.1.0/gems/activesupport-7.1.3.2/lib/active_support/core_ext/enumerable.rb:218:in `compact_blank'
    from /var/lib/gems/3.1.0/gems/git_fame-3.1.1/lib/git_fame/command.rb:140:in `filter'
    from /var/lib/gems/3.1.0/gems/git_fame-3.1.1/lib/git_fame/command.rb:152:in `collector'
    from /var/lib/gems/3.1.0/gems/git_fame-3.1.1/lib/git_fame/command.rb:168:in `result'
    from /var/lib/gems/3.1.0/gems/git_fame-3.1.1/lib/git_fame/command.rb:127:in `block in run'
    from /var/lib/gems/3.1.0/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in `execute_job'
    from /var/lib/gems/3.1.0/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in `block in run'

It does not look project-related because I get the same result on several, very different projects.

Since tty-spinner is the one terminating with an exception, I assume the issue is not directly related to git-fame itself, but it probably has to do with some dependencies incompatibilities. Unfortunately, I know next to nothing about Ruby, so I'm not sure how to troubleshoot this. Please let me know if I can help in any way. git-fame looks really cool and I'd really love to use it.

mably commented 4 months ago

Same probleme here :(

sarna commented 4 months ago

It's a confusing error message, but I'm pretty sure the actual problem is here: https://github.com/oleander/git-fame-rb/blob/78993fc4adef998e8c65f4393df8ef040992e42f/lib/git_fame/command.rb#L140 It's just that the thread in which the spinner runs gets killed by the exception.

By the way, this line does the same thing (call compact_blank on a Hash), so it should have the same issue: https://github.com/oleander/git-fame-rb/blob/78993fc4adef998e8c65f4393df8ef040992e42f/lib/git_fame/command.rb#L160

Now - why does it fail? This method comes from Active Support, and I'm not familiar with Rails at all. This says that compact_blank calls Object#blank. If it's on Object, shouldn't every object respond to it? The doc for it explicitly mentions strings. And yet, on a fresh install:

irb(main):002> require "active_support/core_ext/enumerable"
=> true
irb(main):003> {"foo": "bar"}.compact_blank
/opt/homebrew/lib/ruby/gems/3.3.0/gems/activesupport-7.0.6/lib/active_support/core_ext/enumerable.rb:269:in `block in compact_blank': undefined method `blank?' for an instance of String (NoMethodError)

    reject { |_k, v| v.blank? }
                      ^^^^^^^

Hm.. I bet it's defined in another file. And yep, it is: when you click "source" on APIdock, it'll tell you it's at # File activesupport/lib/active_support/core_ext/object/blank.rb, line 18. Let's try again:

irb(main):004> require "active_support/core_ext/object/blank"
=> true
irb(main):005> {"foo": "bar"}.compact_blank
=> {:foo=>"bar"}

I'll open a pull request.