(this is in the context of Rails, buts its primarily a Ruby question
dealing with exception handling)
This is driving me nuts - I’m tracking down a bug in ActionPack that
causes rails to do a 500 error with no info, or when testing causes an
immediate exit with no information or stack trace.
I’ve tracked it down to ActionView::TemplateError, where numerous
things can happen that cause an exception to be thrown from w/o the
TemplateError. For instance, the following controller will cause the
error to happen:
class FooController < ApplicationController
def bad_file_with_full_path_false
render :file => “unknown”, :use_full_path => false
end
end
And I cannot get the exception to be caught in a test case, no matter
what I do. For example, w/i a standard FooControllerTest:
def test_bad_file_render_with_full_path_false
assert_raises ActionController::MissingTemplate do
get :bad_file_with_full_path_false
end
rescue Exception => e
flunk(“failed”)
end
This just exits - no flunk msg, assert_raise doesn’t catch, nothing.
I also commented out an “ensure” in ActionController::Base#process, to
make sure that wouldn’t halt the exception. It still exits.
I tracked it down into TemplateError via a lot of tedious logging, and
it seems the line here throws an error (though I cant figure out why,
it works in irb):
http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_view/template_error.rb#L79
and this line can also throw an exception, which makes sense because
@file_name refers to a non-existent file:
http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_view/template_error.rb#L29
And of course none of that answers why I can’t rescue the exception
back in my calling code, no matter what I do. Any ideas?
- thanks,
- Rob