Skip to content

Commit

Permalink
get rid of backtrace cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Mar 11, 2010
1 parent b6701db commit ccb66b0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 58 deletions.
13 changes: 1 addition & 12 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,21 +648,11 @@ def error_block!(*keys)
end

def dump_errors!(boom)
backtrace = clean_backtrace(boom.backtrace)
msg = ["#{boom.class} - #{boom.message}:",
*backtrace].join("\n ")
*boom.backtrace].join("\n ")
@env['rack.errors'].puts(msg)
end

def clean_backtrace(trace)
return trace unless settings.clean_trace?

trace.reject { |line|
line =~ /lib\/sinatra.*\.rb/ ||
(defined?(Gem) && line.include?(Gem.dir))
}.map! { |line| line.gsub(/^\.\//, '') }
end

class << self
attr_reader :routes, :before_filters, :after_filters, :templates, :errors

Expand Down Expand Up @@ -1053,7 +1043,6 @@ def caller_locations
set :raise_errors, Proc.new { test? }
set :dump_errors, Proc.new { !test? }
set :show_exceptions, Proc.new { development? }
set :clean_trace, true
set :sessions, false
set :logging, false
set :method_override, false
Expand Down
46 changes: 0 additions & 46 deletions test/settings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,52 +135,6 @@ def foo=(value)
end
end

describe 'clean_trace' do
def clean_backtrace(trace)
Sinatra::Base.new.send(:clean_backtrace, trace)
end

it 'is enabled on Base' do
assert @base.clean_trace?
end

it 'is enabled on Application' do
assert @application.clean_trace?
end

it 'does nothing when disabled' do
backtrace = [
"./lib/sinatra/base.rb",
"./myapp:42",
("#{Gem.dir}/some/lib.rb" if defined?(Gem))
].compact

klass = Class.new(Sinatra::Base)
klass.disable :clean_trace

assert_equal backtrace, klass.new.send(:clean_backtrace, backtrace)
end

it 'removes sinatra lib paths from backtrace when enabled' do
backtrace = [
"./lib/sinatra/base.rb",
"./lib/sinatra/compat.rb:42",
"./lib/sinatra/main.rb:55 in `foo'"
]
assert clean_backtrace(backtrace).empty?
end

it 'removes ./ prefix from backtrace paths when enabled' do
assert_equal ['myapp.rb:42'], clean_backtrace(['./myapp.rb:42'])
end

if defined?(Gem)
it 'removes gem lib paths from backtrace when enabled' do
assert clean_backtrace(["#{Gem.dir}/some/lib"]).empty?
end
end
end

describe 'run' do
it 'is disabled on Base' do
assert ! @base.run?
Expand Down

0 comments on commit ccb66b0

Please sign in to comment.