From 5f7eed68bca37bc5a391b23911102392857b0a6f Mon Sep 17 00:00:00 2001 From: Nick Townsend Date: Tue, 11 Nov 2014 07:37:36 -0800 Subject: [PATCH] Remove unnecessary entries from default backtrace When the --backtrace (or --trace) command line option is not supplied Rake lowers the noise level in exception backtraces by building a regular expression containing all the system library paths and using it to exclude backtrace entries that match. This doesn't always go far enough, particularly in RVM environments when many gem paths are added. This commit reverses that approach and only include backtrace entries that fall within the Capfile and list of tasks imported thereafter. If the full unexpurgated backtrace is required then the --backtrace and --trace options supply it as before. --- CHANGELOG.md | 15 +++++++++++++++ lib/capistrano/application.rb | 12 ++++++++++++ lib/capistrano/dsl/task_enhancements.rb | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b2c2488..3a0787fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,21 @@ Reverse Chronological Order: https://github.com/capistrano/capistrano/compare/v3.2.1...HEAD +* Enhancement (@townsen): Remove unnecessary entries from default backtrace + + When the `--backtrace` (or `--trace`) command line option is not supplied + Rake lowers the noise level in exception backtraces by building + a regular expression containing all the system library paths and + using it to exclude backtrace entries that match. + + This does not always go far enough, particularly in RVM environments when + many gem paths are added. This commit reverses that approach and _only_ + include backtrace entries that fall within the Capfile and list of tasks + imported thereafter. This makes reading exceptions much easier on the eye. + + If the full unexpurgated backtrace is required then the --backtrace + and --trace options supply it as before. + * Disable loading stages configs on `cap -T` * Enhancements (@townsen) * Fix matching on hosts with custom ports or users set diff --git a/lib/capistrano/application.rb b/lib/capistrano/application.rb index 343e1d71..caefa57a 100644 --- a/lib/capistrano/application.rb +++ b/lib/capistrano/application.rb @@ -61,6 +61,18 @@ module Capistrano end end + def display_error_message(ex) + unless options.backtrace + if loc = Rake.application.find_rakefile_location + whitelist = (@imported.dup << loc[0]).map{|f| File.absolute_path(f, loc[1])} + pattern = %r@^(?!#{whitelist.map{|p| Regexp.quote(p)}.join('|')})@ + Rake.application.options.suppress_backtrace_pattern = pattern + end + trace "(Backtrace restricted to imported tasks)" + end + super + end + def exit_because_of_exception(ex) if respond_to?(:deploying?) && deploying? exit_deploy_because_of_exception(ex) diff --git a/lib/capistrano/dsl/task_enhancements.rb b/lib/capistrano/dsl/task_enhancements.rb index 89728f05..4fceb90b 100644 --- a/lib/capistrano/dsl/task_enhancements.rb +++ b/lib/capistrano/dsl/task_enhancements.rb @@ -53,7 +53,7 @@ module Capistrano end def exit_deploy_because_of_exception(ex) - warn t(:deploy_failed, ex: ex.inspect) + warn t(:deploy_failed, ex: ex.message) invoke 'deploy:failed' exit(false) end