ConradIrwin / pry-rescue

Start a pry session whenever something goes wrong.
MIT License
852 stars 49 forks source link

NoMethodError: undefined method `[]' for nil:NilClass #90

Open jacob-carlborg opened 9 years ago

jacob-carlborg commented 9 years ago

I've run in to an issue with Pry resulting an internal exception. The error only occurs when pry-rescue is loaded. I've been able to reproduce the issue by:

  1. Generating a new Rails application with Rails 4.1.9: rails new foo
  2. Generating a new model with a migration rails g model Bar foo:string
  3. Running the migrations rake db:migrate
  4. Adding a method_missing to Bar like this:
class Bar < ActiveRecord::Base
  def method_missing symbol, *args
    self.foo
  end
end
  1. Starting the rails console rails c
  2. Invoking pry pry
  3. Running the following Bar.new(foo: "asd")

The full stack trace looks like this:

NoMethodError: undefined method `[]' for nil:NilClass
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/last_exception.rb:54:in `bt_source_location_for'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/last_exception.rb:15:in `initialize'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_instance.rb:494:in `new'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_instance.rb:494:in `last_exception='
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_instance.rb:331:in `rescue in handle_line'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_instance.rb:317:in `handle_line'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `catch'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `block in eval'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `catch'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `eval'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/repl.rb:77:in `block in repl'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/repl.rb:67:in `loop'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/repl.rb:67:in `repl'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/repl.rb:38:in `block in start'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/input_lock.rb:61:in `call'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/input_lock.rb:61:in `__with_ownership'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/input_lock.rb:79:in `with_ownership'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/repl.rb:38:in `start'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/repl.rb:15:in `start'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/pry_class.rb:169:in `start'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/pry-0.10.1/lib/pry/core_extensions.rb:43:in `pry'
    from (irb):1
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/railties-4.1.9/lib/rails/commands/console.rb:90:in `start'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/railties-4.1.9/lib/rails/commands/console.rb:9:in `start'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/jacob/.rvm/gems/ruby-2.1.5@foo/gems/railties-4.1.9/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:8:in `require'
vincentwoo commented 8 years ago

Also seeing a similar issue here: https://github.com/ConradIrwin/pry-rescue/issues/66#issuecomment-175922027