# Rescue\_from issue with AWS - uninitialized constant

**URL:** <https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267>\
**Category:** Rails\
**Created:** [April 30, 2008, 8:20am UTC](https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267 "2008-04-30T08:20:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [April 30, 2008, 8:20am UTC](https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267/1 "2008-04-30T08:20:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [April 30, 2008, 9:20am UTC](https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267/2 "2008-04-30T09:20:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [April 30, 2008, 9:56am UTC](https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267/3 "2008-04-30T09:56:54Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [April 30, 2008, 10:36am UTC](https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267/4 "2008-04-30T10:36:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [May 1, 2008, 4:42am UTC](https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267/5 "2008-05-01T04:42:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [May 1, 2008, 12:17pm UTC](https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267/6 "2008-05-01T12:17:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [May 1, 2008, 12:39pm UTC](https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267/7 "2008-05-01T12:39:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [May 1, 2008, 12:30pm UTC](https://www.ruby-forum.com/t/rescue-from-issue-with-aws-uninitialized-constant/136267/8 "2008-05-01T12:30:53Z")

</div>

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
