4

I'm running rails 5, upgraded from 4.2.x

In the console and when running methods that fail, the error doesn't show the line number, I only get to see:

Traceback (most recent call last):
NoMethodError (undefined method `[]' for nil:NilClass)

I made sure development.rb has:

config.log_level = :debug

My gemfile:

source 'https://rubygems.org'

  gem 'rails',              '5.1.2'     # mothership
  gem 'bootstrap-sass'                  # crutches
  gem 'sass-rails'                      # Use SCSS for stylesheets
  gem 'devise'                          # login/sessions
  gem 'devise-i18n'                     # login/sessions
  gem 'haml'                            # markup language
  gem 'uglifier',           '>= 1.3.0'  # Use Uglifier as compressor for JavaScript assets
  gem 'coffee-rails'
  gem 'jquery-rails'                   # Use jquery as the JavaScript library
  gem 'bcrypt',             '~> 3.1.7'  # Use ActiveModel has_secure_password
  gem 'html5_validators'
  gem 'execjs'
  gem 'puma'
  gem 'pg'
  gem 'listen'

  group :development do
    gem 'rails_db'
    gem 'hirb'
    gem "better_errors"
    gem "binding_of_caller"
  end

  group :production do
    gem 'aws-sdk-rails'
    gem 'rails_12factor'
  end

What should I change so I get to see line where error occurs?

Tamer Shlash
  • 9,314
  • 5
  • 44
  • 82
JUlinder
  • 995
  • 1
  • 8
  • 19

1 Answers1

5

If you do something like this in the console:

begin
  your_method_call
rescue => e
  puts e.backtrace
end

You will be able to rescue the exception and print the backtrace. You don't have to puts it, you can do whatever you want with the backtrace, but you get the idea.

Hope this help.

Edward
  • 1,914
  • 13
  • 26
  • 1
    I write this in console: `begin; Assessment.last.score; rescue => e; puts e.backtrace; end` I get `=> nil` – JUlinder Jan 15 '18 at 10:47
  • 1
    `puts` will return nil, but the backtrace should be printed through standard output. Besides that, instead of `puts`, you can assign `e` to a variable and try to access `e.backtrace` manually. – Edward Jan 15 '18 at 17:33