public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added ActiveSupport::BacktraceCleaner and Rails::BacktraceCleaner for cutting 
down on backtrace noise (inspired by the Thoughtbot Quiet Backtrace plugin) 
[DHH]
dhh (author)
Sat Nov 22 09:06:08 -0800 2008
commit  f42c77f927eb49b00e84d355e07de48723d03fcb
tree    2a459814a9708f292c99e9c5e99dd41d2d801353
parent  a026b4c983681b71d876ea37958c3e5bc605acac
...
68
69
70
71
72
73
 
 
74
75
76
...
151
152
153
154
155
156
157
158
159
160
 
 
161
162
163
...
68
69
70
 
 
 
71
72
73
74
75
...
150
151
152
 
 
 
 
 
 
 
153
154
155
156
157
0
@@ -68,9 +68,8 @@ module ActionController #:nodoc:
0
             logger.fatal(exception.to_s)
0
           else
0
             logger.fatal(
0
-              "\n\n#{exception.class} (#{exception.message}):\n    " +
0
-              clean_backtrace(exception).join("\n    ") +
0
-              "\n\n"
0
+              "\n#{exception.class} (#{exception.message}):\n  " +
0
+              clean_backtrace(exception).join("\n  ") + "\n\n"
0
             )
0
           end
0
         end
0
@@ -151,13 +150,8 @@ module ActionController #:nodoc:
0
       end
0
 
0
       def clean_backtrace(exception)
0
-        if backtrace = exception.backtrace
0
-          if defined?(RAILS_ROOT)
0
-            backtrace.map { |line| line.sub RAILS_ROOT, '' }
0
-          else
0
-            backtrace
0
-          end
0
-        end
0
+        defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) ? 
0
+          Rails.backtrace_cleaner.clean(exception.backtrace) : exception.backtrace
0
       end
0
   end
0
 end
...
20
21
22
23
 
 
 
 
 
24
25
26
...
66
67
68
69
70
 
 
71
72
73
...
92
93
94
95
96
97
98
99
100
 
101
...
20
21
22
 
23
24
25
26
27
28
29
30
...
70
71
72
 
 
73
74
75
76
77
...
96
97
98
 
 
 
 
 
 
99
100
0
@@ -20,7 +20,11 @@ module ActionView
0
     end
0
 
0
     def clean_backtrace
0
-      original_exception.clean_backtrace
0
+      if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
0
+        Rails.backtrace_cleaner.clean(original_exception.backtrace)
0
+      else
0
+        original_exception.backtrace
0
+      end
0
     end
0
 
0
     def sub_template_message
0
@@ -66,8 +70,8 @@ module ActionView
0
     end
0
 
0
     def to_s
0
-      "\n\n#{self.class} (#{message}) #{source_location}:\n" +
0
-        "#{source_extract}\n    #{clean_backtrace.join("\n    ")}\n\n"
0
+      "\n#{self.class} (#{message}) #{source_location}:\n" + 
0
+      "#{source_extract}\n    #{clean_backtrace.join("\n    ")}\n\n"
0
     end
0
 
0
     # don't do anything nontrivial here. Any raised exception from here becomes fatal 
0
@@ -92,9 +96,4 @@ module ActionView
0
         end + file_name
0
       end
0
   end
0
-end
0
-
0
-if defined?(Exception::TraceSubstitutions)
0
-  Exception::TraceSubstitutions << [/:in\s+`_run_.*'\s*$/, '']
0
-  Exception::TraceSubstitutions << [%r{^\s*#{Regexp.escape RAILS_ROOT}/}, ''] if defined?(RAILS_ROOT)
0
-end
0
+end
0
\ No newline at end of file
...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
...
291
292
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
295
296
0
@@ -291,24 +291,6 @@ class RescueControllerTest < ActionController::TestCase
0
     assert_equal 'template_error',    templates[ActionView::TemplateError.name]
0
   end
0
 
0
-  def test_clean_backtrace
0
-    with_rails_root nil do
0
-      # No action if RAILS_ROOT isn't set.
0
-      cleaned = @controller.send(:clean_backtrace, @exception)
0
-      assert_equal @exception.backtrace, cleaned
0
-    end
0
-
0
-    with_rails_root Dir.pwd do
0
-      # RAILS_ROOT is removed from backtrace.
0
-      cleaned = @controller.send(:clean_backtrace, @exception)
0
-      expected = @exception.backtrace.map { |line| line.sub(RAILS_ROOT, '') }
0
-      assert_equal expected, cleaned
0
-
0
-      # No action if backtrace is nil.
0
-      assert_nil @controller.send(:clean_backtrace, Exception.new)
0
-    end
0
-  end
0
-
0
   def test_not_implemented
0
     with_all_requests_local false do
0
       with_rails_public_path(".") do
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.3.0 [Edge]*
0
 
0
+* Added ActiveSupport::BacktraceCleaner to cut down on backtrace noise according to filters and silencers [DHH]
0
+
0
 * Added Object#try. ( Taken from http://ozmm.org/posts/try.html ) [Chris Wanstrath]
0
 
0
 * Added Enumerable#none? to check that none of the elements match the block #1408 [Damian Janowski]
...
29
30
31
 
32
33
34
...
29
30
31
32
33
34
35
0
@@ -29,6 +29,7 @@ require 'active_support/callbacks'
0
 require 'active_support/core_ext'
0
 
0
 require 'active_support/buffered_logger'
0
+require 'active_support/backtrace_cleaner'
0
 
0
 require 'active_support/gzip'
0
 require 'active_support/cache'
...
6
7
8
 
9
10
11
...
6
7
8
9
10
11
12
0
@@ -6,6 +6,7 @@ module ActiveSupport
0
   end
0
 end
0
 
0
+# TODO: Turn all this into using the BacktraceCleaner.
0
 class Exception # :nodoc:
0
   def clean_message
0
     Pathname.clean_within message
...
21
22
23
 
24
25
26
27
28
 
 
 
 
 
29
30
31
32
 
33
34
35
...
37
38
39
40
 
41
...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
38
39
40
41
...
43
44
45
 
46
47
0
@@ -21,15 +21,21 @@ module ActiveSupport
0
       Assertion = MiniTest::Assertion
0
     end
0
 
0
+    # TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit
0
   # Test::Unit compatibility.
0
   rescue LoadError
0
     require 'test/unit/testcase'
0
     require 'active_support/testing/default'
0
 
0
+    if defined?(Rails)
0
+      require 'rails/backtrace_cleaner'
0
+      Test::Unit::Util::BacktraceFilter.module_eval { include Rails::BacktraceFilterForTestUnit }
0
+    end
0
+
0
     class TestCase < ::Test::Unit::TestCase
0
       Assertion = Test::Unit::AssertionFailedError
0
       include ActiveSupport::Testing::Default
0
-    end
0
+    end    
0
   end
0
 
0
   class TestCase
0
@@ -37,4 +43,4 @@ module ActiveSupport
0
     include ActiveSupport::Testing::Assertions
0
     extend ActiveSupport::Testing::Declarative
0
   end
0
-end
0
+end
0
\ No newline at end of file
...
3
4
5
 
6
7
8
...
3
4
5
6
7
8
9
0
@@ -3,6 +3,7 @@ require 'test/unit'
0
 gem 'mocha', '>= 0.9.0'
0
 require 'mocha'
0
 
0
+$:.unshift "#{File.dirname(__FILE__)}/../lib"
0
 require 'active_support'
0
 require 'active_support/test_case'
0
 
...
21
22
23
24
 
25
26
27
...
21
22
23
 
24
25
26
27
0
@@ -21,7 +21,7 @@ class ArrayExtAccessTests < Test::Unit::TestCase
0
     assert_equal array[2], array.third
0
     assert_equal array[3], array.fourth
0
     assert_equal array[4], array.fifth
0
-    assert_equal array[41], array.fourty_two
0
+    assert_equal array[41], array.forty_two
0
   end
0
 end
0
 
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.3.0 [Edge]*
0
 
0
+* Added Rails.backtrace_cleaner as an accessor for the Rails::BacktraceCleaner instance used by the framework to cut down on backtrace noise and config/initializers/backtrace_silencers.rb to add your own (or turn them all off) [DHH]
0
+
0
 * Switch from Test::Unit::TestCase to ActiveSupport::TestCase.  [Jeremy Kemper]
0
 
0
 * Added config.i18n settings gatherer to config/environment, auto-loading of all locales in config/locales/*.rb,yml, and config/locales/en.yml as a sample locale [DHH]
...
197
198
199
200
201
 
 
 
 
202
203
204
...
197
198
199
 
 
200
201
202
203
204
205
206
0
@@ -197,8 +197,10 @@ task :copy_configs do
0
   
0
   cp "configs/routes.rb", "#{PKG_DESTINATION}/config/routes.rb"
0
 
0
-  cp "configs/initializers/inflections.rb", "#{PKG_DESTINATION}/config/initializers/inflections.rb"
0
-  cp "configs/initializers/mime_types.rb",  "#{PKG_DESTINATION}/config/initializers/mime_types.rb"
0
+  cp "configs/initializers/backtrace_silencers.rb", "#{PKG_DESTINATION}/config/initializers/backtrace_silencers.rb"
0
+  cp "configs/initializers/inflections.rb",         "#{PKG_DESTINATION}/config/initializers/inflections.rb"
0
+  cp "configs/initializers/mime_types.rb",          "#{PKG_DESTINATION}/config/initializers/mime_types.rb"
0
+  cp "configs/initializers/new_rails_defaults.rb",  "#{PKG_DESTINATION}/config/initializers/new_rails_defaults.rb"
0
 
0
   cp "configs/locales/en.yml", "#{PKG_DESTINATION}/config/locales/en.yml"
0
 
...
39
40
41
 
 
 
 
 
 
 
 
42
43
44
...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
0
@@ -39,6 +39,14 @@ module Rails
0
         nil
0
       end
0
     end
0
+    
0
+    def backtrace_cleaner
0
+      @@backtrace_cleaner ||= begin
0
+        # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded
0
+        require 'rails/backtrace_cleaner'
0
+        Rails::BacktraceCleaner.new
0
+      end
0
+    end
0
 
0
     def root
0
       if defined?(RAILS_ROOT)
...
62
63
64
65
66
67
 
 
 
 
68
69
70
...
62
63
64
 
 
 
65
66
67
68
69
70
71
0
@@ -62,9 +62,10 @@ class AppGenerator < Rails::Generator::Base
0
       m.template "configs/routes.rb", "config/routes.rb"
0
 
0
       # Initializers
0
-      m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb"
0
-      m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb"
0
-      m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb"
0
+      m.template "configs/initializers/backtrace_silencers.rb", "config/initializers/backtrace_silencers.rb"
0
+      m.template "configs/initializers/inflections.rb",         "config/initializers/inflections.rb"
0
+      m.template "configs/initializers/mime_types.rb",          "config/initializers/mime_types.rb"
0
+      m.template "configs/initializers/new_rails_defaults.rb",  "config/initializers/new_rails_defaults.rb"
0
 
0
       # Locale
0
       m.template "configs/locales/en.yml", "config/locales/en.yml"

Comments

henrik Sat Nov 22 12:56:28 -0800 2008 at activesupport/test/core_ext/array_ext_test.rb

Snuck that in, did you? ;)

dancroak Sat Nov 22 18:08:31 -0800 2008

Very pleased to see this, especially the backtrace_silencers.rb initializer. Nice work!