From af14b231053784b74f37c2cd1aa8235a174708ee Mon Sep 17 00:00:00 2001 From: ksss Date: Mon, 3 Apr 2023 22:57:30 +0900 Subject: [PATCH 1/4] Debug at stop when task fail Inspired by https://github.com/ko1/rspec-debug --- lib/rake/application.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/rake/application.rb b/lib/rake/application.rb index 90f81e109..21d4ce770 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -94,10 +94,32 @@ def init(app_name="rake", argv = ARGV) # Backward compatibility for capistrano args = handle_options end + load_debug_at_stop collect_command_line_tasks(args) end end + def load_debug_at_stop_feature + return unless ['1', 'true'].include?(ENV["RAKE_DEBUG"]) + require 'debug/session' + DEBUGGER__::start no_sigint_hook: true, nonstop: true + Rake::Task.prepend Module.new { + def execute(*) + exception = DEBUGGER__::SESSION.capture_exception_frames(/(exe|bin|lib)\/rake/) do + super + end + + if exception + STDERR.puts exception.message + DEBUGGER__::SESSION.enter_postmortem_session exception + raise exception + end + end + } + rescue LoadError + end + private :load_debug_at_stop + # Find the rakefile and then load it and any pending imports. def load_rakefile standard_exception_handling do From 121d369c2b8da447f308a818c81372a5fd886c6c Mon Sep 17 00:00:00 2001 From: ksss Date: Tue, 4 Apr 2023 13:17:07 +0900 Subject: [PATCH 2/4] Simplify --- lib/rake/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rake/application.rb b/lib/rake/application.rb index 21d4ce770..fb380f17e 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -100,7 +100,7 @@ def init(app_name="rake", argv = ARGV) end def load_debug_at_stop_feature - return unless ['1', 'true'].include?(ENV["RAKE_DEBUG"]) + return unless ENV["RAKE_DEBUG"] require 'debug/session' DEBUGGER__::start no_sigint_hook: true, nonstop: true Rake::Task.prepend Module.new { From 52a4f1345b48358e0a649bac2dcc9d996dae3219 Mon Sep 17 00:00:00 2001 From: ksss Date: Tue, 4 Apr 2023 14:06:33 +0900 Subject: [PATCH 3/4] Fix method name --- lib/rake/application.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rake/application.rb b/lib/rake/application.rb index fb380f17e..883dd0b4a 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -94,7 +94,7 @@ def init(app_name="rake", argv = ARGV) # Backward compatibility for capistrano args = handle_options end - load_debug_at_stop + load_debug_at_stop_feature collect_command_line_tasks(args) end end @@ -118,7 +118,7 @@ def execute(*) } rescue LoadError end - private :load_debug_at_stop + private :load_debug_at_stop_feature # Find the rakefile and then load it and any pending imports. def load_rakefile From 473acea817b904b998d53458e5cda33c62193cf7 Mon Sep 17 00:00:00 2001 From: ksss Date: Tue, 4 Apr 2023 14:13:35 +0900 Subject: [PATCH 4/4] Auto collect for Style/StringLiterals --- lib/rake/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rake/application.rb b/lib/rake/application.rb index 883dd0b4a..42849e606 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -101,7 +101,7 @@ def init(app_name="rake", argv = ARGV) def load_debug_at_stop_feature return unless ENV["RAKE_DEBUG"] - require 'debug/session' + require "debug/session" DEBUGGER__::start no_sigint_hook: true, nonstop: true Rake::Task.prepend Module.new { def execute(*)