Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug at stop when task fail #489

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/rake/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Copy link
Member

@hsbt hsbt Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this line simplify like return unless ENV["RAKE_DEBUG"]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with you.
This is a respecting the rspec-debug code. But simplifying it should be fine in most cases.

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
Expand Down