I have a Rails 3 application, currently when an internal error occurs it displays one of the pages listed in:
./views/exceptions/internal_server_error.html.haml
./views/exceptions/internal_server_error.json.erb
How can I get the HTML 500 error page to display a stack trace of the exception? I am running Apache not Webrick and I want the exception to display in both production and dev. modes, as this is an internal app. I tried displaying #exception in the internal_server_error.html.haml page but it wasn't populated.
If you want to show the full stack trace in production, comment out the following line in your config/environments/production.rb:
config.consider_all_requests_local = false
It's a pretty poorly named configuration option, but that is what Rails uses to determine whether or not to wire up the exception handling middleware.
It only worked for us when we set the value to true, not commenting it out, i.e., config.consider_all_requests_local = true
Related
For some reason one of my cucumber tests seem to fail both on the poltergeist driver and from the rails server.
I am getting a full trace on the browser crash but almost nothing on the server side.
When I open the Capybara screenshot I just see
Internal Server Error
undefined method name for nil:NilClass
When I tail the test.log
Completed 500 Internal Server Error in 0ms (Elasticsearch: 0.0ms)
(And no trace)
I have tried
to set config.action_dispatch.show_exceptions = true
the b flag (but it's only showing the detailed trace for the Capybara error
(my config level is set to :debug already in my environment file)
How can I get the full backtrace on the server side ?
EDIT
Capybara 2.13.0
Rails 5.0.2
everything commented in backtrace_silencers
I got something from this answer !
So the solution was to allow rescuing the exception in ActionController::Base. In my env file I had the following lines that were misleading
# There are two ways to allow Rails to rescue exceptions:
#
# 1) Tag your scenario (or feature) with #allow-rescue
#
# 2) Set the value below to true. Beware that doing this globally is not
# recommended as it will mask a lot of errors for you!
#
ActionController::Base.allow_rescue = false
And by adding the #allow-rescue tag I got more comprehensive error trace showing in my test.log, along with a frontend error view
If you (like me) do not use Cucumber but Capybara this answer might help you, too.
In config/environments/test.rb set
config.action_dispatch.show_exceptions = true
Developing a rails app on localhost, whenever there is an error you can see the error in detail on the rails page that comes up. But, on Heroku, the only thing that appears when there is an error, is "We're sorry, but something went wrong." with no information. I've seen the logs, and that doesn't seem to help. Is there a way to replace that generic Heroku error page, with the detailed Rails error page?
This isn't a heroku-specific issue, but a production environment one. In any production setting, you can display full errors on by changing this line in your config/environments/production.rb
config.consider_all_requests_local = false
to
config.consider_all_requests_local = true
Note that a better alternative so it's not visible to users is to continue to display the production style error, and tail the log files instead using:
heroku logs --app <yourappname> --tail
This will run a stream of the log file so you don't miss anything rather than just the last 40 lines.
If you aren't seeing enough information, then in config/environments/production add or change the log_level to debug
config.log_level = :info
Or you could reset the log level using an environment variable, so you can just remove it and restart rather than redeploying with:
heroku config:add LOG_LEVEL=DEBUG --app <yourappname>
This could get you going..
routes.rb
match "/404", :to => "exceptions#some_error"
match "/500", :to => "exceptions#some_error"
#add some more?
so then,
class ExceptionsController < ApplicationController
def some_error
#exception = env["action_dispatch.exception"]
#status_code = ActionDispatch::ExceptionWrapper.new(env, #exception).status_code
end
end
a view page finally, to display sort of exception, you will be fixing.
In your rails app, under config/environments/production.rb, try changing
config.consider_all_requests_local = false
to
config.consider_all_requests_local = true
Note: You may want to set up a new environment and deploy that to Heroku when you want to see the normal rails error messages. Maybe something like staging or testing since you don't want users seeing these kinds of errors on a live site.
I feel your pain. Try running heroku run rails console for a clearer error. Hope that helps
I'm trying to use exception_notification for the first time. I watched the Railscast and followed instructions from the author in http://smartinez87.github.io/exception_notification/. Everything seems to work fine with some sort of exceptions but not with others.
I tested and received email error notificatios from my dev environment with errors such as "An ActionView::Template::Error occurred in static_pages#home:". But, there are some Exceptions such as RoutingException and RecordNotFound that are not being catched by ExceptionNotification, and I don't know why, as I have not any rescue_from strategy of any kind in my application_controller.
I'm using rails 3.2.12 and checked the middleware stack array, and I can see ExceptionNotification is just the last one, and it seems that some kind of exceptions does not go their way down the stack, so Exception Notification is not aware of them.
So, the question are: what am i doing wrong? what is the difference between ActionController::RoutingError or ActiveRecord::RecordNotFound which are not catched by ExceptionNotification and ActionView::Template::Error which is catched and causes Exception Notification to send the notification email to my inbox.
Thanks in advance
These exception types are being ignored as part of the default configuration of that gem. See line 25 here: https://github.com/smartinez87/exception_notification/blob/master/lib/exception_notifier.rb which currently reads:
##ignored_exceptions = %w{ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError ActionController::UnknownFormat}
You can override this behavior in your environment file (i.e. development.rb, etc).
Example to notify on ALL errors:
config.middleware.use ExceptionNotifier,
ignore_exceptions: []
Example to add RuntimeError to the default ignore list:
config.middleware.use ExceptionNotifier,
ignore_exceptions: ExceptionNotifier.default_ignore_exceptions + [RuntimeError]
I've got problem with migrating rails 2.x -> 3.2.13
At some point, after fixing a few things, I get Completed 500 Internal Server Error in 76ms without any traceback.
development.rb
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
Why there is no traceback and how to fix this?
you probably solved it but I wanted to share my couple of hours debugging about this issue as it can be very annoying. In short, I was having the same problem - 500 internal server error without any log of the exception thrown. It was happening only for exceptions thrown in the action view templates - any ActionView::Template::Error exception. For example, missing partial, invalid route.
My specific problem was using this ruby statistics module:
http://derrick.pallas.us/ruby-stats/
directly in the initializers directory which works great in rails 2.x. It defined Array.sum method which is already defined in rails 3 under Enumerable.sum. The problem with the redefine is that Array.sum no longer works with arrays of strings which is what rails was trying to do with ActionView::Template::Error.source_extract method - when trying to extract the source of the error in template, it uses the Enumerable.sum method which is redefined in a wrong way. Thus, another exception happened TypeError: cannot convert String into Fixnum and the original exception was not logged, neither was the new one. I had to do a backtrace and go through many of the internal calls to see where is the issue.
So, for everyone not seeing the actual exceptions thrown in your ActionView templates, check if you have not redefined a rails method that is used internally in rails.
I have a view named new.html.erb with the following code:
<%= some_non_existent_thing.imaginary_method %>
Now, I only see one simple 500 error page, like that:
500 Internal Server Error
If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.
Shouldn't I see a pretty formatted page with some information about the exception?
I'm not sure I miss something here, but I believe rails used to show the full error page in development environment when there is something wrong in the view.
Are you sure that you are running the development environment? Check that RAILS_ENV=development or that you are running rails server -e development.
Then check your development.rb file, you should have the following line in it
config.consider_all_requests_local = true
If you happen to have an exception inside an exception, Rails has a middleware that catches it and returns a FAILSAFE_RESPONSE with the following copy:
500 Internal Server Error
If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.
A nice way to troubleshoot this is to compare your custom error code with the sample code provided in the Rails 4.2.0 guides.
I'm pointing to that particular version because that whole section was removed in the Rails 5.0.0 guides.
Ideally, you should keep your error views, layout, and controller as free of logic as possible, to avoid running into this issue.
Firstly, as Anton mentions in the answer below, confirm that your config/environments/development.rb has:
config.consider_all_requests_local = true
and that you are running the server in development mode.
I had ensured the above and still observed the error.
This happened in my case, because my logger had some errors. I was using a custom log formatter, which used the String#% method to format the log. % seems to be very buggy and leads to all these weird errors. I figured this one out by adding a debugger line to the controller method and stepping through into the implicit render function call. It hit the bug and reported it as a malformed format string error.
This was the log formatter I was using before, which caused the bugs [I had added it to an initializer file]:
class Logger::SimpleFormatter
def call(severity, time, progname, msg)
"%-7s #{msg}\n" % severity
end
end
These modifications fixed the bug:
class Logger::SimpleFormatter
def call(severity, time, progname, msg)
severity_prefix = "[#{severity}]".ljust(7)
"#{severity_prefix} #{msg}\n"
end
end
This happens if the code is not compilable, for example if you have an if statement missing an end.