mirror of https://github.com/rails/rails
Revert "Merge pull request #39304 from zenspider/zenspider/backtrace_filter_should_never_return_empty"
This reverts commit2eb7aa111b
, reversing changes made to0b28f0c39c
. Rails backtrace cleaner needs to be able to return empty traces to separate application code from the framework code and not report exceptions that happen inside only framework code. See345de17caf/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb (L72)
.
This commit is contained in:
parent
345de17caf
commit
d98d749222
|
@ -540,9 +540,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
output = StringIO.new
|
output = StringIO.new
|
||||||
backtrace_cleaner = ActiveSupport::BacktraceCleaner.new
|
backtrace_cleaner = ActiveSupport::BacktraceCleaner.new
|
||||||
def backtrace_cleaner.clean(bt, _)
|
backtrace_cleaner.add_silencer { true }
|
||||||
[]
|
|
||||||
end
|
|
||||||
|
|
||||||
env = { "action_dispatch.show_exceptions" => true,
|
env = { "action_dispatch.show_exceptions" => true,
|
||||||
"action_dispatch.logger" => Logger.new(output),
|
"action_dispatch.logger" => Logger.new(output),
|
||||||
|
|
|
@ -104,29 +104,28 @@ module ActiveSupport
|
||||||
add_silencer { |line| line.start_with?(RbConfig::CONFIG["rubylibdir"]) }
|
add_silencer { |line| line.start_with?(RbConfig::CONFIG["rubylibdir"]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Process +ary+ via +filters+ using +method+, ensuring
|
|
||||||
# _something_ gets returned.
|
|
||||||
def process_collection(ary, filters, method)
|
|
||||||
filters.reduce(ary) { |bt, f| bt.public_send(method) { |line| f.call(line) } }
|
|
||||||
end
|
|
||||||
|
|
||||||
# Use @filters to transform the backtrace via map
|
|
||||||
def filter_backtrace(backtrace)
|
def filter_backtrace(backtrace)
|
||||||
process_collection backtrace, @filters, :map
|
@filters.each do |f|
|
||||||
|
backtrace = backtrace.map { |line| f.call(line) }
|
||||||
|
end
|
||||||
|
|
||||||
|
backtrace
|
||||||
end
|
end
|
||||||
|
|
||||||
# Use @silencers to reject parts of the backtrace. Guarantee
|
|
||||||
# something non-empty is returned.
|
|
||||||
def silence(backtrace)
|
def silence(backtrace)
|
||||||
result = process_collection backtrace, @silencers, :reject
|
@silencers.each do |s|
|
||||||
result.first ? result : backtrace.dup
|
backtrace = backtrace.reject { |line| s.call(line) }
|
||||||
|
end
|
||||||
|
|
||||||
|
backtrace
|
||||||
end
|
end
|
||||||
|
|
||||||
# Use @silencers to select parts of the backtrace. Guarantee
|
|
||||||
# something non-empty is returned.
|
|
||||||
def noise(backtrace)
|
def noise(backtrace)
|
||||||
result = backtrace.select { |line| @silencers.any? { |s| s.call(line) } }
|
backtrace.select do |line|
|
||||||
result.first ? result : backtrace.dup
|
@silencers.any? do |s|
|
||||||
|
s.call(line)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,17 +42,6 @@ class BacktraceCleanerSilencerTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class BacktraceCleanerShouldNeverReturnEmpty < ActiveSupport::TestCase
|
|
||||||
test "backtrace should return a backtrace no matter what" do
|
|
||||||
@bc = ActiveSupport::BacktraceCleaner.new
|
|
||||||
@bc.add_silencer { |line| true }
|
|
||||||
|
|
||||||
bt = %w[ first second third ]
|
|
||||||
|
|
||||||
assert_equal bt, @bc.clean(bt.dup)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class BacktraceCleanerMultipleSilencersTest < ActiveSupport::TestCase
|
class BacktraceCleanerMultipleSilencersTest < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
@bc = ActiveSupport::BacktraceCleaner.new
|
@bc = ActiveSupport::BacktraceCleaner.new
|
||||||
|
@ -114,15 +103,15 @@ class BacktraceCleanerDefaultFilterAndSilencerTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should silence gems from the backtrace" do
|
test "should silence gems from the backtrace" do
|
||||||
backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb", "other/file.rb" ]
|
backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
|
||||||
result = @bc.clean(backtrace)
|
result = @bc.clean(backtrace)
|
||||||
assert_equal %w[other/file.rb], result
|
assert_empty result
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should silence stdlib" do
|
test "should silence stdlib" do
|
||||||
backtrace = ["#{RbConfig::CONFIG["rubylibdir"]}/lib/foo.rb", "other/file.rb"]
|
backtrace = ["#{RbConfig::CONFIG["rubylibdir"]}/lib/foo.rb"]
|
||||||
result = @bc.clean(backtrace)
|
result = @bc.clean(backtrace)
|
||||||
assert_equal %w[other/file.rb], result
|
assert_empty result
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should preserve lines that have a subpath matching a gem path" do
|
test "should preserve lines that have a subpath matching a gem path" do
|
||||||
|
|
Loading…
Reference in New Issue