The new rescue_from in edge rails seems to conflict with
ActionWebService, which I need for various other purposes. When I
define, for example (with AWS gem installed):
OK, so AWS interfers with the inheritance chain I guess, but if I
define:
The problem seems to be that ActionController::RoutingError is an unknown constant at the time that file is being interpreted. If that's correct that's unrelated to rescue_from, it just happens that Ruby sees a constant, tries to resolve it because it is an argument of a method it is calling (rescue_from), and fails.
The first thing I'd try is to pass the exception class name instead of the exception class itself:
> OK, so AWS interfers with the inheritance chain I guess, but if I
> define:
The problem seems to be that ActionController::RoutingError is an
unknown constant at the time that file is being interpreted. If that's
correct that's unrelated to rescue_from, it just happens that Ruby
sees a constant, tries to resolve it because it is an argument of a
method it is calling (rescue_from), and fails.
The first thing I'd try is to pass the exception class name instead of
the exception class itself:
For Kip: AWS defines a constant ActionController somewhere within its namespace. If putting a leading "::" works it would happen that rescue_from is invoked somehow within that namespace[*] and "ActionContoller" is found relative to something instead of as the top-level constant. The one in AWS does not have a child RoutingError constant, and since constant name resolution has no backtracking so to speak it fails at that point.
-- fxn
[*] Somehow means the way constant name resolution works.
Very helpful guys, thank you. The String argument to rescue_from
works fine. Of course I made a stupid error for my example:
ActionController::RoutingError is never going to be rescued in this
way (since it relies on a normal controller execution).
Therefore there is still a reason to use rescue_action(_in_public) in
order to handle that error (unless I missed something entirely!)
rescue_from is written in a way that does not assume the exceptions you declare will ever exist. That's why it understands a string with an exception class name as well as an excection class.
In its implementation if a string is unknown as constant by the time some exception is being processed it just ignores it and continues. That's by design.
Very helpful guys, thank you. The String argument to rescue_from
works fine. Of course I made a stupid error for my example:
ActionController::RoutingError is never going to be rescued in this
way (since it relies on a normal controller execution).
Therefore there is still a reason to use rescue_action(_in_public) in
order to handle that error (unless I missed something entirely!)
Why it follows?
rescue_from is written in a way that does not assume the exceptions
you declare will ever exist. That's why it understands a string with
an exception class name as well as an excection class.
I think Kip's point is that ActionController::RoutingError is thrown
when a controller could not be found that matched the url, so having
something in a controller to rescue_from it is futile.