This project is archived and is in readonly mode.
Exceptions in views hard to catch
-
pedz
The diff fixes my issue.
-
Michael Koziarski
- Milestone cleared.
- Assigned user set to Michael Koziarski
I was bitten by this myself today, marking for 3.0
I'd prefer to investigate changing AV to not swallow the exceptions before making this change in rescue_from
-
Michael Koziarski
- Milestone cleared.
-
Yehuda Katz (wycats)
- State changed from new to invalid
I cannot reproduce. If anyone can, please provide better repro information.
-
Evgeniy Dolzhenko
Hopefully this sufficiently illustrates the problem we're having
application_controller.rb
class ApplicationController < ActionController::Base protect_from_forgery layout 'application' rescue_from ActionView::TemplateError, :with => :rescue_template_error def rescue_template_error(template_error) # any exception raised from views will be wrapped in TemplateError # so that you have to examine `template_error.original_exception` and # then use `rescue_action_without_handler` if exception should propagate render :text => "rescued TemplateError" end rescue_from ArgumentError, :with => :rescue_argument_error def rescue_argument_error(argument_error) # this will get called only when raised from controller level render :text => "rescued ArgumentError" end endposts/index.html.erb
<%# will get caught by `rescue_from ActionView::TemplateError` clause %> <% raise ArgumentError, "test ArgumentError" %>posts_controller.rb
class PostsController < ApplicationController def index # will get caught by `rescue_from ArgumentError, :with => :rescue_argument_error` clause raise ArgumentError, "test ArgumentError" end end -
Neeraj Singh
- Tag changed from action_view, exception, templateerror to 3.x, action_view, exception, patch, templateerror
Attached is a patch with test.
-
Neeraj Singh
José Valim provided feedback on the patch. Will be providing a better patch and test soon.
-
Neeraj Singh
Attached is modified patch with test.
-
José Valim
- State changed from invalid to open
- Assigned user changed from Michael Koziarski to José Valim
- Importance changed from to
-
Repository
- State changed from open to resolved
(from [33c5689e2d04aa08759903bc5d1e4de3bf6c35dd]) Exceptions from views should be rescued based on the original exception. If a handler for original exception is missing then apply ActiveView::TemplateError
[#2034 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/33c5689e2d04aa08759903bc5d1e4d... -
Jon Leighton
Here is a workaround for those who are using Rails 2.3. Place in your ApplicationController:
rescue_from ActionView::TemplateError do |exception| rescue_action(exception.original_exception) end
