mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
put backtrace_cleaner to env
This commit is contained in:
parent
970caea5bc
commit
fe7d4f09ef
4 changed files with 27 additions and 18 deletions
|
@ -82,9 +82,9 @@ module ActionDispatch
|
|||
template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
|
||||
:request => Request.new(env),
|
||||
:exception => exception,
|
||||
:application_trace => application_trace(exception),
|
||||
:framework_trace => framework_trace(exception),
|
||||
:full_trace => full_trace(exception)
|
||||
:application_trace => application_trace(env, exception),
|
||||
:framework_trace => framework_trace(env, exception),
|
||||
:full_trace => full_trace(env, exception)
|
||||
)
|
||||
file = "rescues/#{@@rescue_templates[exception.class.name]}"
|
||||
body = template.render(:template => file, :layout => 'rescues/layout')
|
||||
|
@ -130,26 +130,26 @@ module ActionDispatch
|
|||
ActiveSupport::Deprecation.silence do
|
||||
message = "\n#{exception.class} (#{exception.message}):\n"
|
||||
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
|
||||
message << " " << application_trace(exception).join("\n ")
|
||||
message << " " << application_trace(env, exception).join("\n ")
|
||||
logger(env).fatal("#{message}\n\n")
|
||||
end
|
||||
end
|
||||
|
||||
def application_trace(exception)
|
||||
clean_backtrace(exception, :silent)
|
||||
def application_trace(env, exception)
|
||||
clean_backtrace(env, exception, :silent)
|
||||
end
|
||||
|
||||
def framework_trace(exception)
|
||||
clean_backtrace(exception, :noise)
|
||||
def framework_trace(env, exception)
|
||||
clean_backtrace(env, exception, :noise)
|
||||
end
|
||||
|
||||
def full_trace(exception)
|
||||
clean_backtrace(exception, :all)
|
||||
def full_trace(env, exception)
|
||||
clean_backtrace(env, exception, :all)
|
||||
end
|
||||
|
||||
def clean_backtrace(exception, *args)
|
||||
defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) ?
|
||||
Rails.backtrace_cleaner.clean(exception.backtrace, *args) :
|
||||
def clean_backtrace(env, exception, *args)
|
||||
env['action_dispatch.backtrace_cleaner'] ?
|
||||
env['action_dispatch.backtrace_cleaner'].clean(exception.backtrace, *args) :
|
||||
exception.backtrace
|
||||
end
|
||||
|
||||
|
|
|
@ -135,4 +135,11 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
|
|||
get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => Logger.new(output)}
|
||||
assert_match(/puke/, output.rewind && output.read)
|
||||
end
|
||||
|
||||
test 'uses backtrace cleaner from env' do
|
||||
@app = DevelopmentApp
|
||||
cleaner = stub(:clean => ['passed backtrace cleaner'])
|
||||
get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.backtrace_cleaner' => cleaner}
|
||||
assert_match(/passed backtrace cleaner/, body)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -124,7 +124,8 @@ module Rails
|
|||
"action_dispatch.parameter_filter" => config.filter_parameters,
|
||||
"action_dispatch.secret_token" => config.secret_token,
|
||||
"action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
|
||||
"action_dispatch.logger" => Rails.logger
|
||||
"action_dispatch.logger" => Rails.logger,
|
||||
"action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -521,10 +521,11 @@ module ApplicationTests
|
|||
make_basic_app
|
||||
|
||||
assert_respond_to app, :env_config
|
||||
assert_equal app.env_config['action_dispatch.parameter_filter'], app.config.filter_parameters
|
||||
assert_equal app.env_config['action_dispatch.secret_token'], app.config.secret_token
|
||||
assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions
|
||||
assert_equal app.env_config['action_dispatch.logger'], Rails.logger
|
||||
assert_equal app.env_config['action_dispatch.parameter_filter'], app.config.filter_parameters
|
||||
assert_equal app.env_config['action_dispatch.secret_token'], app.config.secret_token
|
||||
assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions
|
||||
assert_equal app.env_config['action_dispatch.logger'], Rails.logger
|
||||
assert_equal app.env_config['action_dispatch.backtrace_cleaner'], Rails.backtrace_cleaner
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue