aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/rescuable.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-11-17 14:49:07 -0500
committerSean Griffin <sean@seantheprogrammer.com>2016-11-17 14:50:41 -0500
commitf48bb1b4ad86bad71ae9c3e5dd3db6b4cb80e4d1 (patch)
tree0dfc8bf23e4c22bc66c9a1042a7f5775983e2cb9 /activesupport/lib/active_support/rescuable.rb
parent8d015dff821875faab3429badbc378dc4c80b90c (diff)
downloadrails-f48bb1b4ad86bad71ae9c3e5dd3db6b4cb80e4d1.tar.gz
rails-f48bb1b4ad86bad71ae9c3e5dd3db6b4cb80e4d1.tar.bz2
rails-f48bb1b4ad86bad71ae9c3e5dd3db6b4cb80e4d1.zip
Call fallback exception handlers with the right exception
The issue presented in #26246 showed a deeper underlying problem. When we fell back to the exception handler for an exceptions cause, we were calling that handler with the outer raised exception. This breaks the calling code's expectations, especially if the exception has methods on it behond those from `StandardError`.
Diffstat (limited to 'activesupport/lib/active_support/rescuable.rb')
-rw-r--r--activesupport/lib/active_support/rescuable.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb
index 135690cc42..7f29c955f9 100644
--- a/activesupport/lib/active_support/rescuable.rb
+++ b/activesupport/lib/active_support/rescuable.rb
@@ -85,14 +85,16 @@ module ActiveSupport
#
# Returns the exception if it was handled and +nil+ if it was not.
def rescue_with_handler(exception, object: self)
- if handler = handler_for_rescue(exception, object: object)
+ handler, exception = handler_for_rescue(exception, object: object)
+ if handler
handler.call exception
exception
end
end
def handler_for_rescue(exception, object: self) #:nodoc:
- case rescuer = find_rescue_handler(exception)
+ rescuer, exception = find_rescue_handler(exception)
+ result = case rescuer
when Symbol
method = object.method(rescuer)
if method.arity == 0
@@ -107,6 +109,7 @@ module ActiveSupport
-> e { object.instance_exec(e, &rescuer) }
end
end
+ [result, exception]
end
private
@@ -121,7 +124,11 @@ module ActiveSupport
end
end
- handler || find_rescue_handler(exception.cause)
+ if handler
+ [handler, exception]
+ else
+ find_rescue_handler(exception.cause)
+ end
end
end