diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-03-11 10:14:50 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-03-11 10:53:01 -0700 |
commit | b76b817629bf1504e3109c9872b250513690561d (patch) | |
tree | 8f9f28e60a6b7f46020b6a4bc4dde39742f916ca /activesupport | |
parent | 0ff6eb34892514b811077ca7dd39340c96836f75 (diff) | |
download | rails-b76b817629bf1504e3109c9872b250513690561d.tar.gz rails-b76b817629bf1504e3109c9872b250513690561d.tar.bz2 rails-b76b817629bf1504e3109c9872b250513690561d.zip |
Use the most highest priority exception handler when cause is set
There was some subtle breakage caused by #18774, when we removed
`#original_exception` in favor of `#cause`. However, `#cause` is
automatically set by Ruby when raising an exception from a rescue block.
With this change, we will use whichever handler has the highest priority
(whichever call to `rescue_from` came last). In cases where the outer
has lower precidence than the cause, but the outer is what should be
handled, cause will need to be explicitly unset.
Fixes #23925
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/rescuable.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb index fcf5553061..73bc52b56f 100644 --- a/activesupport/lib/active_support/rescuable.rb +++ b/activesupport/lib/active_support/rescuable.rb @@ -115,5 +115,15 @@ module ActiveSupport end end end + + def index_of_handler_for_rescue(exception) + handlers = self.class.rescue_handlers.reverse_each.with_index + _, index = handlers.detect do |(klass_name, _), _| + klass = self.class.const_get(klass_name) rescue nil + klass ||= (klass_name.constantize rescue nil) + klass === exception if klass + end + index + end end end |