This project is archived and is in readonly mode.
use backtrace_cleaners when using Deprecation#warn
-
Josh Nichols
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
This seems like something that'd be useful in 2-3-stable, so attached a patch that applies cleanly there.
-
Ed Ruder
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
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
+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
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
Screwed around a bit with mocking the Rails.cleaner. Diff:
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.firstI'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
- Assigned user set to Pratik
-
Rizwan Reza
- Tag changed from bugmash, deprecation to deprecation, help
-
Ryan Bigg
- State changed from new to needs-more-info
Josh, the link to your patch is broken :( Are you able to replicate this?
-
Santiago Pastorino
- 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
- State changed from open to stale
