I have started getting a strange issue in a Rails app, that is proving very difficult to debug.
EOFError
end of file reached
is being raised on some Devise routes. So far I'm getting this on session#destroy and registration#update (I have not been able to try others).
The issue is not occurring in tests, only in development environment.
After stepping through the controllers, the error appears to be raised on the following lines.
registration#update
resource_updated = update_resource(resource, account_update_params)
session#destroy
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
I realise that identifing the cause will likely need much more code. But after several hours trying to debug this I'm at a loss to next steps. I'd be grateful if anyone can:
Suggest how to obtain more useful information when EOFError is
raised. Currently all I'm getting is Completed 500 Internal Server
Error in 2627ms (ActiveRecord: 10.1ms) EOFError - end of file
reached: without much to identify where this is being raised.
Suggest a logical approach to debug this. From my attempts, the
error appears to be coming from the Devise internals, which I don't
think is correct.
Related
This has been stumping me: Rails is throwing this error, after it's finished rendering my views, but before it gets back to the browser:
ActionView::Template::Error (undefined method `start_with?' for #<Proc:0x00005651bfe017f0>)
And... that's it. There's no stack trace. I get shown the standard 500 "We're sorry, but something went wrong" page, despite having config.consider_all_requests_local = true set. There are no further details either in the terminal or in log/development.log.
I can't find any Procs that it might be complaining about, nor can I find any calls to start_with? that might be the cause; I've gone back through Git history and isolated the issue to one commit (this one, if you want to take a look in detail), but nothing within that commit jumps out as being obvious.
Calling a render layout: false does work, as does simplifying my layouts/application.js down to just a <%= yield %>, which makes me think it might be something in there, however - I made no changes to it or any views at all in the commit in which the issue appeared.
What I'd really like to know is how I can get Rails to give me the stack trace for this error, so I can figure out where it's coming from. If you have any ideas where the bug itself might be, those are more than welcome too.
Drop this in an initializer (proc.rb):
class Proc
def start_with?(*args)
puts caller
end
end
So I recently pulled in the Rails best practices gem and it said I should use the current_user.find instead of doing it a different way. The issue is, this of course throws ActiveRecord::RecordNotFound when the current_user doesn't have the record. Now in my integration tests, I explicitly test that a user cannot access another users records. This causes the error to be thrown. The issue is, I want to handle this error since I expect it to be thrown. It's currently making my tests red. How can I get my tests to go green, while still testing that the error is thrown? Any help is clarification on best practices would be greatly appreciated! Thank you!
sidenote
As you can see, I'm attempting to use assert_raise. Which isn't catching the error of course... And assert_field_no_difference is just one of my helper methods..
Also, I've been searching for answers for a while now. Most people address how to handle it within the controller, in respect to render a page, or redirecting, but I haven't found anyone addressing how to handle it as expected behavior within a test.
my integration test
test "tries to edit resource not associated with user" do
login(#user)
assert_field_no_difference #resource, 'url' do
assert_raise ActiveRecord::RecordNotFound do
put community_resource_path(#resource), params: { community_resource: {
url: 'http://www.example.com'}}
end
end
end
error being thown as expected
Error:
Community::ResourcesFlowsTest#test_tries_to_edit_resource_not_associated_with_user:
ActiveRecord::RecordNotFound: Couldn't find Community::Resource with 'id'=1 [WHERE "community_resources"."user_id" = $1]
app/controllers/community/resources_controller.rb:106:in `set_allowable_access_resource'
test/integration/community/resources_flows_test.rb:110:in `block in <class:ResourcesFlowsTest>'
I just launched a completely rebuilt in rails website and am using New Relic for error monitoring. I've been getting a lot of errors and alerts for what I'm guessing is people using bookmarks for pages/paths that no longer exist and possibly some hot linking.
What is the best way to resolve this situation so that I stop getting the alerts?
How about ignoring those errors?
ignore_errors - A comma separated list of Exception classes which will
be ignored
In addition, the error collector can be customized programmatically
for more control over filtering. In your application initialization,
you can register a block with the Agent to be called when an error is
detected. The block should return the error to record, or nil if the
error is to be ignored. For example:
config.after_initialize do
::NewRelic::Agent.ignore_error_filter do |error|
if error.message =~ /gateway down/
nil
elsif
error.class.name == "InvalidLicenseException"
StandardError.new "We should never see this..."
else
error
end
end
end
(source)
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 am upgrading my application from Rails 2.3.14 to Rails 3.0.1
I always get this error if there is any error in the view
Development mode eh? Here is the error - #<ActionView::Template::Error: ActionView::Template::Error>
app/controllers/application_controller.rb:158:in `render_500'
This is the code written for render_500 in application_controller.rb
def render_500(error)
if Rails.env.production?
render :file => Rails.root.join('public','access_denied.html'), :status => 500
else
raise Exception, I18n.t('str_error')+" - #{error.inspect}"
end
end
I am debugging the code now by writing puts statements.
Please help me with a solution. Thanks in advance.
Well, the application is behaving properly. The Development mode eh? Here is the error is the string inside I18n.t('str_error'). You are just raising an exception, and rendering nothing, just this string, so there is no problem.
Template error can be many things, but the one more common is assets that are not precompiled and stuff. Do a little research on this, maybe it is the problem, but keep in mind that the code provided is working as expected.