Rescue_from issue with AWS - uninitialized constant

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):

rescue_from ActionController::RoutingError, :with
=> :page_not_found

I get the exception:

uninitialized constant
ActionWebService::Dispatcher::ActionController::Base

OK, so AWS interfers with the inheritance chain I guess, but if I
define:

rescue_from Object::ActionController::RoutingError, :with
=> :page_not_found

I get no errors, but then the rescue_from method isn’t invoked either.

Anyone got any advice? I can get around this with
rescue_action_in_public, but thats just not as nice.

Cheers, --Kip

On Apr 30, 2008, at 8:19 , Kip wrote:

The new rescue_from in edge rails

rescue_from comes with Rails 2.

ActionWebService::Dispatcher::ActionController::Base

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:

 rescue_from "ActionController::RoutingError", :with

=> :page_not_found

If the exception gets raised it will be certainly already loaded and
rescue_from will be able to find the match.

– fxn

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:

 rescue_from "ActionController::RoutingError", :with  

=> :page_not_found

I’ve seen ::ActionController::RoutingError work too I think.

Fred

On Apr 30, 2008, at 9:56 , Frederick C. wrote:

I’ve seen ::ActionController::RoutingError work too I think.

Good.

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!)

Cheers, --Kip

On May 1, 2008, at 4:41 , Kip wrote:

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.

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.

– fxn

On May 1, 2008, at 12:29 , Frederick C. wrote:

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.

Oh yes.

On 1 May 2008, at 11:16, Xavier N. wrote:

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.

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs