diff options
author | Joshua Peek <josh@joshpeek.com> | 2010-01-16 21:34:35 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2010-01-16 21:34:35 -0600 |
commit | eb39d0f7b999f09c4e13f035634887a8f5592443 (patch) | |
tree | 4155dd1bb0cb878ff0aec9f36c113e4a094ab498 /activesupport/lib | |
parent | d2d4acf02793580e0f0c1bc380389527325b6254 (diff) | |
download | rails-eb39d0f7b999f09c4e13f035634887a8f5592443.tar.gz rails-eb39d0f7b999f09c4e13f035634887a8f5592443.tar.bz2 rails-eb39d0f7b999f09c4e13f035634887a8f5592443.zip |
Use backtrace cleaner for dev mode exception page
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/backtrace_cleaner.rb | 32 | ||||
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 8 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/exception.rb | 47 |
3 files changed, 28 insertions, 59 deletions
diff --git a/activesupport/lib/active_support/backtrace_cleaner.rb b/activesupport/lib/active_support/backtrace_cleaner.rb index 0e262c003e..6fab565646 100644 --- a/activesupport/lib/active_support/backtrace_cleaner.rb +++ b/activesupport/lib/active_support/backtrace_cleaner.rb @@ -9,7 +9,7 @@ module ActiveSupport # Example: # # bc = BacktraceCleaner.new - # bc.add_filter { |line| line.gsub(Rails.root, '') } + # bc.add_filter { |line| line.gsub(Rails.root, '') } # bc.add_silencer { |line| line =~ /mongrel|rubygems/ } # bc.clean(exception.backtrace) # will strip the Rails.root prefix and skip any lines from mongrel or rubygems # @@ -18,10 +18,19 @@ module ActiveSupport def initialize @filters, @silencers = [], [] end - + # Returns the backtrace after all filters and silencers has been run against it. Filters run first, then silencers. - def clean(backtrace) - silence(filter(backtrace)) + def clean(backtrace, kind = :silent) + filtered = filter(backtrace) + + case kind + when :silent + silence(filtered) + when :noise + noise(filtered) + else + filtered + end end # Adds a filter from the block provided. Each line in the backtrace will be mapped against this filter. @@ -51,21 +60,28 @@ module ActiveSupport @silencers = [] end - private def filter(backtrace) @filters.each do |f| backtrace = backtrace.map { |line| f.call(line) } end - + backtrace end - + def silence(backtrace) @silencers.each do |s| backtrace = backtrace.reject { |line| s.call(line) } end - + + backtrace + end + + def noise(backtrace) + @silencers.each do |s| + backtrace = backtrace.select { |line| s.call(line) } + end + backtrace end end diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 6360a4614e..7213b24f2d 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -30,7 +30,7 @@ module ActiveSupport # # ActiveSupport::Cache.lookup_store(:memory_store) # # => returns a new ActiveSupport::Cache::MemoryStore object - # + # # ActiveSupport::Cache.lookup_store(:mem_cache_store) # # => returns a new ActiveSupport::Cache::MemCacheStore object # @@ -97,7 +97,7 @@ module ActiveSupport # Ruby objects, but don't count on every cache store to be able to do that. # # cache = ActiveSupport::Cache::MemoryStore.new - # + # # cache.read("city") # => nil # cache.write("city", "Duckburgh") # cache.read("city") # => "Duckburgh" @@ -139,7 +139,7 @@ module ActiveSupport # # cache.write("today", "Monday") # cache.fetch("today") # => "Monday" - # + # # cache.fetch("city") # => nil # cache.fetch("city") do # "Duckburgh" @@ -198,7 +198,7 @@ module ActiveSupport # You may also specify additional options via the +options+ argument. # The specific cache store implementation will decide what to do with # +options+. - # + # # For example, MemCacheStore supports the +:expires_in+ option, which # tells the memcached server to automatically expire the cache item after # a certain period: diff --git a/activesupport/lib/active_support/core_ext/exception.rb b/activesupport/lib/active_support/core_ext/exception.rb index b594fbae8e..ef801e713d 100644 --- a/activesupport/lib/active_support/core_ext/exception.rb +++ b/activesupport/lib/active_support/core_ext/exception.rb @@ -1,50 +1,3 @@ module ActiveSupport FrozenObjectError = RUBY_VERSION < '1.9' ? TypeError : RuntimeError end - -# TODO: Turn all this into using the BacktraceCleaner. -class Exception # :nodoc: - # Clean the paths contained in the message. - def self.clean_paths(string) - require 'pathname' unless defined? Pathname - string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path| - Pathname.new(path).cleanpath - end - end - - def clean_message - Exception.clean_paths(message) - end - - TraceSubstitutions = [] - FrameworkStart = /action_controller\/dispatcher\.rb/.freeze - FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/.freeze - - def clean_backtrace - backtrace.collect do |line| - substituted = TraceSubstitutions.inject(line) do |result, (regexp, sub)| - result.gsub regexp, sub - end - Exception.clean_paths(substituted) - end - end - - def application_backtrace - before_framework_frame = nil - before_application_frame = true - - trace = clean_backtrace.reject do |line| - before_framework_frame ||= (line =~ FrameworkStart) - non_app_frame = (line =~ FrameworkRegexp) - before_application_frame = false unless non_app_frame - before_framework_frame || (non_app_frame && !before_application_frame) - end - - # If we didn't find any application frames, return an empty app trace. - before_application_frame ? [] : trace - end - - def framework_backtrace - clean_backtrace.grep FrameworkRegexp - end -end |