rails / thor

Thor is a toolkit for building powerful command-line interfaces.
http://whatisthor.com/
MIT License
5.12k stars 553 forks source link

superclass mismatch for class Command (TypeError) #721

Closed johan-smits closed 4 years ago

johan-smits commented 4 years ago

When I update my rails project thor from 0.20.3 to 1.0.0 or 1.0.1 I cannot run tests anymore. It gives me this trackback:

Traceback (most recent call last):
    82: from bin/rails:4:in `<main>'
    81: from ~/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `require'
    80: from ~/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:291:in `load_dependency'
    79: from ~/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `block in require'
    78: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    77: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    76: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    75: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    74: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    73: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/commands.rb:18:in `<top (required)>'
    72: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/command.rb:46:in `invoke'
    71: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/command/base.rb:69:in `perform'
    70: from /usr/lib/ruby/vendor_ruby/thor.rb:369:in `dispatch'
    69: from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:126:in `invoke_command'
    68: from /usr/lib/ruby/vendor_ruby/thor/command.rb:27:in `run'
    67: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/commands/test/test_command.rb:33:in `perform'
    66: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/test_unit/runner.rb:39:in `run'
    65: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/test_unit/runner.rb:50:in `load_tests'
    64: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/test_unit/runner.rb:50:in `each'
    63: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/test_unit/runner.rb:50:in `block in load_tests'
    62: from ~/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `require'
    61: from ~/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:291:in `load_dependency'
    60: from ~/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `block in require'
    59: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    58: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    57: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    56: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    55: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    54: from ~/test/controllers/fonts_controller_test.rb:1:in `<top (required)>'
    53: from ~/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `require'
    52: from ~/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:291:in `load_dependency'
    51: from ~/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `block in require'
    50: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    49: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    48: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    47: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    46: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    45: from ~/test/test_helper.rb:4:in `<top (required)>'
    44: from ~/vendor/bundle/ruby/2.5.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
    43: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    42: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    41: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    40: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    39: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    38: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/test_help.rb:11:in `<top (required)>'
    37: from ~/vendor/bundle/ruby/2.5.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
    36: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    35: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    34: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    33: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    32: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    31: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/generators/test_case.rb:3:in `<top (required)>'
    30: from ~/vendor/bundle/ruby/2.5.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
    29: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    28: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    27: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    26: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    25: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    24: from ~/vendor/bundle/ruby/2.5.0/gems/railties-6.0.2.2/lib/rails/generators.rb:6:in `<top (required)>'
    23: from ~/vendor/bundle/ruby/2.5.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
    22: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    21: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    20: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    19: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    18: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    17: from ~/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/group.rb:1:in `<top (required)>'
    16: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:49:in `require_relative'
    15: from ~/vendor/bundle/ruby/2.5.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
    14: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    13: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    12: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    11: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    10: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
     9: from ~/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/base.rb:1:in `<top (required)>'
     8: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:49:in `require_relative'
     7: from ~/vendor/bundle/ruby/2.5.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
     6: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
     5: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
     4: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
     3: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
     2: from ~/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
     1: from ~/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/command.rb:1:in `<top (required)>'
~/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/command.rb:2:in `<class:Thor>': superclass mismatch for class Command (TypeError)

I run on Debian testing but I have installed ruby-bundler which also installs ruby-thor@0.19.4-1. Not sure if this is the case but why does this break?

rafaelfranca commented 4 years ago

Thor 0.19 has different superclass for Command. So if both versions are loaded you will get this error.

https://github.com/erikhuda/thor/commit/35ab20dc5400d5c3bbefdfc74a9536849e9cca4b.

bundler vendor thor with a different namespace to avoid this problem and others, so the fact debian doesn't respect that project choice is an issue in the OS, not in thor or even bundler.

johan-smits commented 4 years ago

@rafaelfranca thanks for the swift reply. I opened up a ticket at Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=955405

paulschreiber commented 4 years ago

@johan-smits did you find a workaround?

On Ubuntu 20.04, I ended up running:

dpkg -r --force-depends  ruby-thor
gem install thor
paulschreiber commented 4 years ago

Leaving my machine in the above state caused problems because of broken dependencies. I ended up building a .deb for thor 1.0.1 myself.

Build the thor gem:

Install fpm

Build the .deb

Install the .deb

johan-smits commented 4 years ago

@paulschreiber I did not, the project stalled for me so no need to continue. A new upload to Debian would fix it I guess. But the bugreport is not very active.

paulschreiber commented 4 years ago

@johan-smits I filed a report on Ubuntu as well: https://bugs.launchpad.net/ubuntu/+source/ruby-thor/+bug/1885424

richard-viney commented 4 years ago

I added gem 'thor', '~> 0.20.3' to my Rails app's gems.rb(aka Gemfile) in order to make this go away.

fjorba commented 3 years ago

I turns out that using a custom installed Ruby 2.7.1, instead of the Debian Buster default 2.5.5, this error does not appear, at least with one of the two Ruby packages where I've found it.

Previously, I tried to install Thor 1.0.1, using the standard Debian package practices:

$ apt install gem2deb
$ gem2deb thor
$ sudo apt install ruby-thor_1.0.1-1_all.deb

However, it didn't change the error message:

[...]/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/command.rb:2:in `<class:Thor>': superclass mismatch for class Command (TypeError)

So I suspect that there is some incompatibility with thor 1.0.1 and some Ruby versions pre-2.7.1.

Lapizistik commented 3 years ago

As others may still run into this problem: sudo gem install bundler helps (as long as /usr/local/bin is in your path before /usr/bin, this should be the default).

Yesid4Code commented 3 years ago

@richard-viney

I added gem 'thor', '~> 0.20.3' to my Rails app's gems.rb(aka Gemfile) in order to make this go away. This option really worked for me ( I added the current version: 1.1.0 ). Thanks a lot

MubarakSULAYMAN commented 3 years ago

Somehow, following the guide and using the caveat instruction for "Windows Subsystem for Linux" which advised to disable the spring and listen gems - e.g rails new blog --skip-spring --skip-listen really fixed it on my Ubuntu 20.04.

jubilee2 commented 1 year ago

As others may still run into this problem: sudo gem install bundler helps (as long as /usr/local/bin is in your path before /usr/bin, this should be the default).

update bundler from 2.4.0 to 2.4.3 to solve issue!