Skip to content

Commit 43c0177

Browse files
authored
Merge pull request #489 from ksss/debug
Debug at stop when task fail
2 parents 693dcf9 + 473acea commit 43c0177

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/rake/application.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,32 @@ def init(app_name="rake", argv = ARGV)
9494
# Backward compatibility for capistrano
9595
args = handle_options
9696
end
97+
load_debug_at_stop_feature
9798
collect_command_line_tasks(args)
9899
end
99100
end
100101

102+
def load_debug_at_stop_feature
103+
return unless ENV["RAKE_DEBUG"]
104+
require "debug/session"
105+
DEBUGGER__::start no_sigint_hook: true, nonstop: true
106+
Rake::Task.prepend Module.new {
107+
def execute(*)
108+
exception = DEBUGGER__::SESSION.capture_exception_frames(/(exe|bin|lib)\/rake/) do
109+
super
110+
end
111+
112+
if exception
113+
STDERR.puts exception.message
114+
DEBUGGER__::SESSION.enter_postmortem_session exception
115+
raise exception
116+
end
117+
end
118+
}
119+
rescue LoadError
120+
end
121+
private :load_debug_at_stop_feature
122+
101123
# Find the rakefile and then load it and any pending imports.
102124
def load_rakefile
103125
standard_exception_handling do

0 commit comments

Comments
 (0)