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

Error when running rails console #184

Closed
aar0nr opened this issue Jan 27, 2016 · 9 comments
Closed

Error when running rails console #184

aar0nr opened this issue Jan 27, 2016 · 9 comments

Comments

@aar0nr
Copy link

aar0nr commented Jan 27, 2016

Using:

  • rails (4.2.5.1)
  • web-console (3.1.0)

Running:

rails console

Outputs:

Running via Spring preloader in process 6529
~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/railtie.rb:245:in `each_registered_block': undefined method `each' for nil:NilClass (NoMethodError)
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/railtie.rb:224:in `run_console_blocks'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application.rb:472:in `block in run_console_blocks'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine/railties.rb:13:in `each'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine/railties.rb:13:in `each'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application.rb:472:in `run_console_blocks'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:438:in `load_console'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:58:in `initialize'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `new'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `start'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  from ~/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top (required)>'
  from ~/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
  from ~/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require'
  from ~/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
  from ~/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
  from ~/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load'
  from ~/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `block in load'
  from ~/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
  from ~/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load'
  from ~/.rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  from ~/.rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  from -e:1:in `<main>'
@gsamokovarov
Copy link
Collaborator

Can you give us a bit more context? Are you sure web-console is the cause of that error?

@aar0nr
Copy link
Author

aar0nr commented Jan 27, 2016

Yes, I created a brand new rails app, and when I update web-console to v3.1.0 I am unable to start a rails console session via bin/rails console. If I downgrade to v3.0.0 it works fine.

@joelmichael
Copy link

I am also sure it is the cause of the error.

[243, 252] in /Users/joel/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.5.1/lib/rails/railtie.rb
   243:       klass = self.class
   244:       while klass.respond_to?(type)
   245:         if klass == Object && type.to_s == 'console'
   246:           debugger
   247:         end
=> 248:         klass.public_send(type).each(&block)
   249:         klass = klass.superclass
   250:       end
   251:     end
   252:   end
(byebug) Object.method :console
#<Method: Class(Kernel)#console>
(byebug) Object.method(:console).source_location
["/Users/joel/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-3.1.0/lib/web_console/extensions.rb", 9]
(byebug) 

@kapso
Copy link

kapso commented Jan 28, 2016

+1 getting the same issue

@prathamesh-sonpatki
Copy link
Member

@gsamokovarov A similar issue was reported on rails/rails#23300. I created sample app - https://github.com/prathamesh-sonpatki/web-console-console-issue, please check.

@Eric-Guo
Copy link

+1, I can confirm, it's due to web-console instead of Rails master branch, if using web-console v3.0.0, such error not happen, no matter using puma 2.16.0 or rails master, so must a bug between v3.0.0 and v3.1.0

@Eric-Guo
Copy link

Confirm revert #182 will resolve this issue.

@gsamokovarov
Copy link
Collaborator

Holy moly. Thank you folks for the investigation. I have a fix and will release 3.1.1 ASAP.

gsamokovarov added a commit that referenced this issue Jan 28, 2016
Railties can hook themselves into the `rails console` with:

```ruby
class Railtie < ::Rails::Railtie
  console do
    # Do something here.
  end
end
```

Now, since I introduced the `#console` method in `Kernel`, every object
responded to it, so this block was tried to be run on railties that
respond to it.

Marking the `#console` method _explicitly_ as `module_function`
solves this problem as it makes it `private` and the `#respond_to?`
calls during the railties initialization no longer lie.

Fixes #184.
@aar0nr
Copy link
Author

aar0nr commented Jan 28, 2016

Thank you @gsamokovarov , I appreciate the quick fix!

gsamokovarov added a commit to gsamokovarov/rails that referenced this issue Feb 4, 2016
This is a reaction to a [bug] we hit in web-console. The cause of it was
a `Kernel` extension called `#console` that was public and was fighting
over Railties with console block to be run on `rails console`. We solved
it by making the method private. We did that through `module_function`
so `::Kernel.console` can be invoked even in `BasicObject`.

I'm proposing to make most of the core Active Support `Kernel`
extensions `module_function` as well. Those are currently public and we
are polluting every `Object` public interface with them.

```ruby
>> Object.new.respond_to? :silence_warnings
=> true

>> Object.new.respond_to? :with_warnings
=> true

>> Object.new.respond_to? :enable_warnings
=> true

>> Object.new.respond_to? :suppress
=> true
``

Some extensions like `Kernel#class_eval` should be public, but most of
them don't really need to be.

[bug]: rails/web-console#184
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

6 participants