This project is archived and is in readonly mode.

#3015 ✓stale
Josh Nichols

use backtrace_cleaners when using Deprecation#warn

Reported by Josh Nichols | August 8th, 2009 @ 10:51 PM

On ticket #2932, we're seeing the deprecation warning isn't displaying the line that is using the deprecated code. Instead, it's showing some from inside the Rails framework.

There's already infrastructure in place for removing Rails framework stuff from backtraces, the Rails.backtrace_cleaner, so it would make sense to pass the callstack through it. The top item of the cleaned callstack should be then be the line where the deprecated code was called.

Comments and changes to this ticket

  • Josh Nichols

    Josh Nichols August 8th, 2009 @ 11:09 PM

    I've attached a patch which does this. I didn't include any tests, because I didn't find any good examples of tests verifying the use of Rails.backtrace_cleaner in other parts of the code base.

    I was able to verify its use though:

    rails 3015-verification
    cd 3015-verification
    script/generate scaffold beers
    # edit app/controller/beers_controller.rb to use redirect to formatted_beers_url in a few places
    script/server
    # go to http://localhost:3000/beers then click new, and create
    # check server log to see the deprecation notice points at the line the deprecated formated_beers_url was used.
    
  • Josh Nichols

    Josh Nichols August 8th, 2009 @ 11:33 PM

    This seems like something that'd be useful in 2-3-stable, so attached a patch that applies cleanly there.

  • Ed Ruder

    Ed Ruder August 9th, 2009 @ 05:49 AM

    I tried to reproduce the problem on frozen rails release=2.3.3, but couldn't. I followed Josh's steps to verify the patch, before applying the patch, and always got a reference to the correct line in my beers controller.

    P.S. When I executed script/generate scaffold beers (plural model name) per Josh's steps, the scaffold generator created a broken app! It warned of a plural model/using singularized, and created a Beer model, but the BeersController referenced a Beers model! Is that a known bug?

  • Josh Nichols

    Josh Nichols August 9th, 2009 @ 07:52 AM

    The scaffold should probably be the singular 'beer', pardon my much anticipation for some plural beers which were to happen later in the eveing. The issue you are running into seem to be more generator oriented. Use script/generate beer instead.

  • Dan Croak

    Dan Croak August 9th, 2009 @ 04:06 PM

    +1 verified 2-3-stable patch applies cleanly and produces a nice deprecation warning with file and line number:

    DEPRECATION WARNING: formatted_beers_url() has been deprecated.
    Please pass format to the standard beers_url method instead.

    (called from create at /Users/dancroak/dev/3015/app/controllers/beers_controller.rb:48)

    For anyone else looking to verify, my steps, including generating a Rails app with the applied patch:

    downloaded the 3015-stable patch into a bugmash directory
    git apply ~/bugmash/3015-stable-clean_deprecation_callstack.patch
    ruby ~/dev/rails/railties/bin/rails 3015
    cd 3015
    script/generate scaffold beer
    rake db:migrate
    edit line 48 of app/controllers/beers_controller.rb to include redirect_to(formatted_beers_url)
    script/server
    created a beer, observed the backtrace in the development log
    
  • Dan Croak

    Dan Croak August 9th, 2009 @ 04:43 PM

    I've attached a patch that is a test to make sure the "called from #{method} at #{file}:#{line_number}" shows in the deprecation warning, but it passes without Josh's patch.

    I did some print debugging without Josh's patch and the warnings all had method/file/line_number information in the deprecation.

  • Dan Croak

    Dan Croak August 9th, 2009 @ 05:18 PM

    Screwed around a bit with mocking the Rails.cleaner. Diff:

    http://gist.github.com/164808

    But getting an error:

    test_assert_deprecation_backtrace_is_cleaned(DeprecationTest):
    NoMethodError: You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.first

    I'm giving up on an "integration" test with Rails.cleaner.

    I'd say Josh's patch is commit-able as-is. My unit test may be useful for regressions but not as proof of this particular patch.

  • Dan Croak

    Dan Croak August 9th, 2009 @ 05:32 PM

    • Assigned user set to “Pratik”
  • Rizwan Reza

    Rizwan Reza January 20th, 2010 @ 11:13 AM

    • Tag changed from bugmash, deprecation to deprecation, help
  • Ryan Bigg

    Ryan Bigg June 12th, 2010 @ 03:31 AM

    • State changed from “new” to “needs-more-info”

    Josh, the link to your patch is broken :( Are you able to replicate this?

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:37 PM

    • State changed from “needs-more-info” to “open”
    • Importance changed from “” to “”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:37 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages