Skip to content
This repository
Browse code

Update Exception extension to show the first few framework frames in …

…an application trace.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2654 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 57f43473d73906232340ccbb6b4651dfd99bc1eb 1 parent 98c1735
Nicholas Seckar authored October 16, 2005
4  activesupport/CHANGELOG
... ...
@@ -1,6 +1,8 @@
1 1
 *SVN*
2 2
 
3  
-* Added Extension extension to provide support for clean backtraces. [Nicholas Seckar]
  3
+* Update Exception extension to show the first few framework frames in an application trace. [Nicholas Seckar] 
  4
+
  5
+* Added Exception extension to provide support for clean backtraces. [Nicholas Seckar]
4 6
 
5 7
 * Updated whiny nil to be more concise and useful. [Nicholas Seckar]
6 8
 
8  activesupport/lib/active_support/core_ext/exception.rb
@@ -13,6 +13,12 @@ def clean_backtrace
13 13
   end
14 14
   
15 15
   def application_backtrace
16  
-    clean_backtrace.reject { |line| line =~ /(vendor|dispatch|ruby|script\/\w+)/ }
  16
+    before_application_frame = true
  17
+    
  18
+    clean_backtrace.reject do |line|
  19
+      non_app_frame = !! (line =~ /vendor|dispatch|ruby|script\/\w+/)
  20
+      before_application_frame = false unless non_app_frame
  21
+      non_app_frame && ! before_application_frame
  22
+    end
17 23
   end
18 24
 end
14  activesupport/test/core_ext/exception_test.rb
@@ -21,4 +21,18 @@ def test_clean_backtrace
21 21
     assert_equal ['bhal.rb', 'rawh hid den stuff is not here', 'almost all'], e.clean_backtrace
22 22
   end
23 23
   
  24
+  def test_app_backtrace
  25
+    Exception::TraceSubstitutions << [/\s*hidden.*/, '']
  26
+    e = get_exception RuntimeError, 'RAWR', ['bhal.rb', ' vendor/file.rb some stuff', 'almost all']
  27
+    assert_kind_of Exception, e
  28
+    assert_equal ['bhal.rb', 'almost all'], e.application_backtrace
  29
+  end
  30
+  
  31
+  def test_app_backtrace_with_before
  32
+    Exception::TraceSubstitutions << [/\s*hidden.*/, '']
  33
+    e = get_exception RuntimeError, 'RAWR', ['vendor/file.rb some stuff', 'bhal.rb', ' vendor/file.rb some stuff', 'almost all']
  34
+    assert_kind_of Exception, e
  35
+    assert_equal ['vendor/file.rb some stuff', 'bhal.rb', 'almost all'], e.application_backtrace
  36
+  end
  37
+  
24 38
 end

0 notes on commit 57f4347

Please sign in to comment.
Something went wrong with that request. Please try again.