aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-11-22 18:06:08 +0100
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-11-22 18:06:08 +0100
commitf42c77f927eb49b00e84d355e07de48723d03fcb (patch)
tree2a459814a9708f292c99e9c5e99dd41d2d801353 /actionpack
parenta026b4c983681b71d876ea37958c3e5bc605acac (diff)
downloadrails-f42c77f927eb49b00e84d355e07de48723d03fcb.tar.gz
rails-f42c77f927eb49b00e84d355e07de48723d03fcb.tar.bz2
rails-f42c77f927eb49b00e84d355e07de48723d03fcb.zip
Added ActiveSupport::BacktraceCleaner and Rails::BacktraceCleaner for cutting down on backtrace noise (inspired by the Thoughtbot Quiet Backtrace plugin) [DHH]
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/rescue.rb14
-rw-r--r--actionpack/lib/action_view/template_error.rb17
-rw-r--r--actionpack/test/controller/rescue_test.rb18
3 files changed, 12 insertions, 37 deletions
diff --git a/actionpack/lib/action_controller/rescue.rb b/actionpack/lib/action_controller/rescue.rb
index ec8e9b92d5..9c24c3def4 100644
--- a/actionpack/lib/action_controller/rescue.rb
+++ b/actionpack/lib/action_controller/rescue.rb
@@ -68,9 +68,8 @@ module ActionController #:nodoc:
logger.fatal(exception.to_s)
else
logger.fatal(
- "\n\n#{exception.class} (#{exception.message}):\n " +
- clean_backtrace(exception).join("\n ") +
- "\n\n"
+ "\n#{exception.class} (#{exception.message}):\n " +
+ clean_backtrace(exception).join("\n ") + "\n\n"
)
end
end
@@ -151,13 +150,8 @@ module ActionController #:nodoc:
end
def clean_backtrace(exception)
- if backtrace = exception.backtrace
- if defined?(RAILS_ROOT)
- backtrace.map { |line| line.sub RAILS_ROOT, '' }
- else
- backtrace
- end
- end
+ defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) ?
+ Rails.backtrace_cleaner.clean(exception.backtrace) : exception.backtrace
end
end
end
diff --git a/actionpack/lib/action_view/template_error.rb b/actionpack/lib/action_view/template_error.rb
index bcce331773..37cb1c7c6c 100644
--- a/actionpack/lib/action_view/template_error.rb
+++ b/actionpack/lib/action_view/template_error.rb
@@ -20,7 +20,11 @@ module ActionView
end
def clean_backtrace
- original_exception.clean_backtrace
+ if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
+ Rails.backtrace_cleaner.clean(original_exception.backtrace)
+ else
+ original_exception.backtrace
+ end
end
def sub_template_message
@@ -66,8 +70,8 @@ module ActionView
end
def to_s
- "\n\n#{self.class} (#{message}) #{source_location}:\n" +
- "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
+ "\n#{self.class} (#{message}) #{source_location}:\n" +
+ "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
end
# don't do anything nontrivial here. Any raised exception from here becomes fatal
@@ -92,9 +96,4 @@ module ActionView
end + file_name
end
end
-end
-
-if defined?(Exception::TraceSubstitutions)
- Exception::TraceSubstitutions << [/:in\s+`_run_.*'\s*$/, '']
- Exception::TraceSubstitutions << [%r{^\s*#{Regexp.escape RAILS_ROOT}/}, ''] if defined?(RAILS_ROOT)
-end
+end \ No newline at end of file
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 32c6c013f1..63f9827f4a 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -291,24 +291,6 @@ class RescueControllerTest < ActionController::TestCase
assert_equal 'template_error', templates[ActionView::TemplateError.name]
end
- def test_clean_backtrace
- with_rails_root nil do
- # No action if RAILS_ROOT isn't set.
- cleaned = @controller.send(:clean_backtrace, @exception)
- assert_equal @exception.backtrace, cleaned
- end
-
- with_rails_root Dir.pwd do
- # RAILS_ROOT is removed from backtrace.
- cleaned = @controller.send(:clean_backtrace, @exception)
- expected = @exception.backtrace.map { |line| line.sub(RAILS_ROOT, '') }
- assert_equal expected, cleaned
-
- # No action if backtrace is nil.
- assert_nil @controller.send(:clean_backtrace, Exception.new)
- end
- end
-
def test_not_implemented
with_all_requests_local false do
with_rails_public_path(".") do