提交 7ba531be 编写于 作者: J Jonathan Hefner

Silence Rake task backtraces

Silence Rake task backtraces, similar to Rails::BacktraceCleaner.
Application lines are preserved, but all other lines are hidden.

This also affects unrecognized tasks, causing the backtrace to be hidden
entirely.  Closes #39524.
Co-authored-by: NPetrik <petrik@deheus.net>
上级 27a1ca2b
......@@ -19,6 +19,9 @@ def perform(task, args, config)
load "rails/tasks.rb"
rake.init("rails", [task, *args])
rake.load_rakefile
if Rails.respond_to?(:root)
rake.options.suppress_backtrace_pattern = /\A(?!#{Regexp.quote(Rails.root.to_s)})/
end
rake.standard_exception_handling { rake.top_level }
end
end
......
......@@ -25,6 +25,22 @@ def test_gems_tasks_are_loaded_first_than_application_ones
assert $task_loaded
end
test "task backtrace is silenced" do
add_to_config <<-RUBY
rake_tasks do
task :boom do
raise "boom"
end
end
RUBY
backtrace = rails("boom", allow_failure: true).lines.grep(/:\d+:in /)
app_lines, framework_lines = backtrace.partition { |line| line.start_with?(app_path) }
assert_not_empty app_lines
assert_empty framework_lines
end
test "task is protected when previous migration was production" do
with_rails_env "production" do
rails "generate", "model", "product", "name:string"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册