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
Related
Poltergeist accepts a blacklist and whitelist while configuring it as a driver for Capybara. The documentation states:
Poltergeist supports URL blacklisting, which allows you to prevent scripts from running on designated domains.
While this is great, it doesn't help my issue where I would like to block certain assets from being requested/loaded as it is causing issues in my Travis-CI where those assets are returning as 500 Server Errors and causing my tests to fail even though they should be green.
URIs should be blocked as:
['/stylesheet/*', 'some-image-name.jpg']
Is this possible to do with Poltergeist? Or is there a way to have a Capybara cucumber test not fail just because an asset returned a 500 server error?
Capybara.register_driver :poltergeist do |app|
poltergeist_opts = {
window_size: [1280, 1024],
url_blacklist: ['/stylesheets/select_box_arrow.gif', '/stylesheets/ui-icons_ffffff_256x240.png']
}
Capybara::Poltergeist::Driver.new(app, poltergeist_opts)
end
Poltergeist blacklists are specified as wildcard strings (* and . as special characters) that are substring matched to the full urls being requested, so yes you can block the specific things you want by specifying exactly what you've shown in your question in the url_blacklist array. However, if the 500 error is coming from your app you'd be much better off just fixing your app/test setup so that it doesn't return a server error when requesting valid assets (fix asset deploy on travis, etc).
The other option is to prevent Capybara from failing tests on server errors - Capybara.raise_server_errors = false - however that could possibly hide server errors you care about.
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 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
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.