From 6dd6ecc0e8ef8a019d4ccf850064ffa78bb384a8 Mon Sep 17 00:00:00 2001 From: Perry Smith (IBM) Date: Tue, 14 Apr 2009 15:25:59 -0500 Subject: [PATCH] Change to rescue_with_handler to special case template errors When an exception happens inside a view, it is wrapped with an ActionView::TemplateError. The lookup for the rescue_with_handler then fails to find the handle for the original exception. This patch special cases the template error to look also at the wrapped exception and if there is a handler for that exception, then call it and ignore the wrapping. --- activesupport/lib/active_support/rescuable.rb | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb index c27c4dd..1d9b079 100644 --- a/activesupport/lib/active_support/rescuable.rb +++ b/activesupport/lib/active_support/rescuable.rb @@ -69,8 +69,22 @@ module ActiveSupport # Tries to rescue the exception by looking up and calling a registered handler. def rescue_with_handler(exception) - if handler = handler_for_rescue(exception) - handler.arity != 0 ? handler.call(exception) : handler.call + # Special case ActionView::TemplateError exception. Look at + # original exception as well + if ((handler = handler_for_rescue(exception)).nil? && + exception.class == ActionView::TemplateError && + (temp_exception = exception.original_exception) && + (temp_handler = handler_for_rescue(temp_exception))) + handler = temp_handler + exception = temp_exception + end + + if handler + if handler.arity != 0 + handler.call(exception) + else + handler.call + end true # don't rely on the return value of the handler end end -- 1.6.1