diff options
author | Peter McCracken <peter.mccracken@shopify.com> | 2017-05-10 13:30:41 -0400 |
---|---|---|
committer | Peter McCracken <peter.mccracken@shopify.com> | 2017-05-10 13:33:46 -0400 |
commit | 4fc2ea11811c50fb1f7c5baba6d4c20532a5a00c (patch) | |
tree | c7d112a64892e101cc57ed1ec73f11b444ab611f /activesupport/lib/active_support/rescuable.rb | |
parent | 8b69e32412cc2867b5fdd9a33cf4e4e759057e95 (diff) | |
download | rails-4fc2ea11811c50fb1f7c5baba6d4c20532a5a00c.tar.gz rails-4fc2ea11811c50fb1f7c5baba6d4c20532a5a00c.tar.bz2 rails-4fc2ea11811c50fb1f7c5baba6d4c20532a5a00c.zip |
handle loops in the cause chain in Rescuable#rescue_with_handler
Diffstat (limited to 'activesupport/lib/active_support/rescuable.rb')
-rw-r--r-- | activesupport/lib/active_support/rescuable.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb index ee6592fb5a..12ec8bf1b8 100644 --- a/activesupport/lib/active_support/rescuable.rb +++ b/activesupport/lib/active_support/rescuable.rb @@ -84,12 +84,18 @@ module ActiveSupport # end # # Returns the exception if it was handled and +nil+ if it was not. - def rescue_with_handler(exception, object: self) + def rescue_with_handler(exception, object: self, visited_exceptions: []) + visited_exceptions << exception + if handler = handler_for_rescue(exception, object: object) handler.call exception exception elsif exception - rescue_with_handler(exception.cause, object: object) + if visited_exceptions.include?(exception.cause) + nil + else + rescue_with_handler(exception.cause, object: object, visited_exceptions: visited_exceptions) + end end end |