Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ Layout/CaseIndentation:
Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable

# Exceptions should be rescued with `AllExceptionsExceptOnesWeMustNotRescue`
Lint/RescueException:
Enabled: true
2 changes: 1 addition & 1 deletion lib/rake/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def standard_exception_handling # :nodoc:
rescue OptionParser::InvalidOption => ex
$stderr.puts ex.message
exit(false)
rescue Exception => ex
rescue AllExceptionsExceptOnesWeMustNotRescue => ex
# Exit with error message
display_error_message(ex)
exit_because_of_exception(ex)
Expand Down
2 changes: 1 addition & 1 deletion lib/rake/promise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def chore
stat :will_execute, item_id: object_id
begin
@result = @block.call(*@args)
rescue Exception => e
rescue AllExceptionsExceptOnesWeMustNotRescue => e
@error = e
end
stat :did_execute, item_id: object_id
Expand Down
9 changes: 9 additions & 0 deletions lib/rake/rake_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
require "rake/application"

module Rake
module AllExceptionsExceptOnesWeMustNotRescue
# These exceptions are dangerous to rescue as rescuing them
# would interfere with things we should not interfere with.
AVOID_RESCUING = [NoMemoryError, SignalException, Interrupt, SystemExit]

def self.===(exception)
AVOID_RESCUING.none? { |ar| ar === exception }
end
end

class << self
# Current Rake Application
Expand Down
2 changes: 1 addition & 1 deletion lib/rake/thread_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def join
stat :joining
@join_cond.wait unless @threads.empty?
stat :joined
rescue Exception => e
rescue AllExceptionsExceptOnesWeMustNotRescue => e
stat :joined
$stderr.puts e
$stderr.print "Queue contains #{@queue.size} items. " +
Expand Down