Skip to content

Commit 5e4bc4f

Browse files
committed
Change rescue Exception to limit rescuing critical ones
Taken from https://github.com/rspec/rspec-support/blob/v3.13.0/lib/rspec/support.rb#L145-L153
1 parent 2a9baec commit 5e4bc4f

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

lib/rake.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@
2121
# IN THE SOFTWARE.
2222
#++
2323

24-
module Rake; end
24+
module Rake
25+
module AllExceptionsExceptOnesWeMustNotRescue
26+
# These exceptions are dangerous to rescue as rescuing them
27+
# would interfere with things we should not interfere with.
28+
AVOID_RESCUING = [NoMemoryError, SignalException, Interrupt, SystemExit]
29+
30+
def self.===(exception)
31+
AVOID_RESCUING.none? { |ar| ar === exception }
32+
end
33+
end
34+
end
2535

2636
require_relative "rake/version"
2737

lib/rake/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def standard_exception_handling # :nodoc:
218218
rescue OptionParser::InvalidOption => ex
219219
$stderr.puts ex.message
220220
exit(false)
221-
rescue Exception => ex
221+
rescue AllExceptionsExceptOnesWeMustNotRescue => ex
222222
# Exit with error message
223223
display_error_message(ex)
224224
exit_because_of_exception(ex)

lib/rake/promise.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def chore
6262
stat :will_execute, item_id: object_id
6363
begin
6464
@result = @block.call(*@args)
65-
rescue Exception => e
65+
rescue AllExceptionsExceptOnesWeMustNotRescue => e
6666
@error = e
6767
end
6868
stat :did_execute, item_id: object_id

lib/rake/thread_pool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def join
4747
stat :joining
4848
@join_cond.wait unless @threads.empty?
4949
stat :joined
50-
rescue Exception => e
50+
rescue AllExceptionsExceptOnesWeMustNotRescue => e
5151
stat :joined
5252
$stderr.puts e
5353
$stderr.print "Queue contains #{@queue.size} items. " +

0 commit comments

Comments
 (0)