Skip to content
This repository

add --suppress-backtrace option #68

Merged
merged 2 commits into from over 1 year ago

2 participants

James M. Lawrence Jim Weirich
James M. Lawrence
quix commented August 06, 2011

The original commit in #64 allowed the user to add paths to SUPPRESS_PATHS in case of annoyance. For instance if gems are not installed under CONFIG['prefix'] then this would have the effect of --trace being permanently on.

That flexibility was removed in the final commit. I've added it back with a command-line option this time, and using a regexp instead of a list of paths.

If you decide against the option then I would recommend at least having Rake.application.options.suppress_backtrace_pattern available in code, or some other escape hatch.

Jim Weirich
Owner

Good catch. I'm travelling at the moment, but I'll see what I can do when I get home. Thanks.

James M. Lawrence
quix commented August 07, 2011

The last commit excludes the paths

ruby -rrbconfig -rpp -e 'pp RbConfig::CONFIG.reject { |k,_| k !~ /(prefix|libdir)/ }'

Though the arbitrariness of this is giving me second thoughts, it seems to be OK.

Jim Weirich jimweirich merged commit 18f4919 into from October 23, 2012
Jim Weirich jimweirich closed this October 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Aug 06, 2011
James M. Lawrence add --suppress-backtrace option 1b53296
Aug 07, 2011
James M. Lawrence suppress more backtrace lines using RbConfig info 18f4919
This page is out of date. Refresh to see the latest.
5  lib/rake/application.rb
@@ -376,6 +376,11 @@ def standard_rake_options
376 376
             options.silent = true
377 377
           }
378 378
         ],
  379
+        ['--suppress-backtrace PATTERN', "Suppress backtrace lines matching regexp PATTERN. Ignored if --trace is on.",
  380
+          lambda { |value|
  381
+            options.suppress_backtrace_pattern = Regexp.new(value)
  382
+          }
  383
+        ],
379 384
         ['--system',  '-g',
380 385
           "Using system wide (global) rakefiles (usually '~/.rake/*.rake').",
381 386
           lambda { |value| options.load_system = true }
14  lib/rake/backtrace.rb
... ...
@@ -1,15 +1,17 @@
1 1
 module Rake
2 2
   module Backtrace
3  
-    SUPPRESSED_PATHS = [
4  
-      RbConfig::CONFIG["prefix"],
5  
-      File.join(File.dirname(__FILE__), ".."),
6  
-    ].map { |f| Regexp.quote(File.expand_path(f)) }
  3
+    SUPPRESSED_PATHS =
  4
+      RbConfig::CONFIG.values_at(*RbConfig::CONFIG.
  5
+                                 keys.grep(/(prefix|libdir)/)) + [
  6
+        File.join(File.dirname(__FILE__), ".."),
  7
+      ].map { |f| Regexp.quote(File.expand_path(f)) }
7 8
 
8 9
     SUPPRESS_PATTERN = %r!(\A#{SUPPRESSED_PATHS.join('|')}|bin/rake:\d+)!
9 10
 
10  
-    # Elide backtrace elements which match one of SUPPRESS_PATHS.
11 11
     def self.collapse(backtrace)
12  
-      backtrace.reject { |elem| elem =~ SUPPRESS_PATTERN }
  12
+      pattern = Rake.application.options.suppress_backtrace_pattern ||
  13
+                SUPPRESS_PATTERN
  14
+      backtrace.reject { |elem| elem =~ pattern }
13 15
     end
14 16
   end
15 17
 end
18  test/test_rake_backtrace.rb
@@ -46,4 +46,22 @@ def test_multi_collapse
46 46
     assert_match %r!\A#{Regexp.quote Dir.pwd}/Rakefile:3!, lines[3]
47 47
     assert_match %r!\ATasks:!, lines[4]
48 48
   end
  49
+
  50
+  def test_suppress_option
  51
+    rakefile %q{
  52
+      task :baz do
  53
+        raise "bazzz!"
  54
+      end
  55
+    }
  56
+
  57
+    lines = rake("baz").split("\n")
  58
+    assert_equal "rake aborted!", lines[0]
  59
+    assert_equal "bazzz!", lines[1]
  60
+    assert_match %r!Rakefile!, lines[2]
  61
+
  62
+    lines = rake("--suppress-backtrace", "R.k.file", "baz").split("\n")
  63
+    assert_equal "rake aborted!", lines[0]
  64
+    assert_equal "bazzz!", lines[1]
  65
+    refute_match %r!Rakefile!, lines[2]
  66
+  end
49 67
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.