Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Routing Errors won't get rescued properly

#1684

When requesting an uri with no matching route the application raises the following exception:


      You have a nil object when you didn't expect it!
The error occurred while evaluating nil.request=
    /Users/LacKac/Working/Lab/test/vendor/rails/actionpack/lib/action_controller/base.rb:518:in `process_without_filters'

Reproducing the error is simple:

The problem is that the call_with_exception method won't find the original request and response objects in the env hash because they're not yet set. I attached a patch which solves the problem by creating new request and response objects if they're not set. It's basically the same as in this commit by josh: http://github.com/rails/rails/co...

I couldn't come up with a test since not having those two env keys set will create new request and response objects wich will make it impossible to test based on changes made to a TestResponse instance.

Reported by LacKac · January 2nd, 2009 @ 12:23 AM

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. josh
    josh
    • Milestone cleared.
    • State changed from new to open
    • Assigned user set to josh

    January 2nd, 2009 @ 03:49 AM

  2. josh
    josh

    Ugh, I knew this was going to causes problems. Thanks for catching it and making the proper patch.

    Any chance I could bother you to create some unit tests to go with it? :)

    I don't want this to accidently break again.

    January 2nd, 2009 @ 03:56 AM

  3. LacKac
    LacKac

    It was tricky since all of the @controller, @request and @response instance variables are ignored when call_with_exception is called but eventually I came up with a test which is based on the return value of the method.

    It's attached. This also includes the fix so ignore my previous patch.

    January 2nd, 2009 @ 05:04 AM

  4. Repository
    Repository
    • State changed from open to resolved

    (from [606176a55b90c27687ae17f40fd1af0a86b62246]) Fixed call_with_exception for Routing Errors [#1684 state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    January 2nd, 2009 @ 04:44 PM