ActiveSupport::Reloader should not report exception

Since it always delegate to an actual executor that does report
them already, this cause exceptions to be reported twice.

Fix: https://github.com/rails/rails/issues/46100
This commit is contained in:
Jean Boussier 2022-09-22 16:52:28 +02:00
parent 2d36ebc729
commit c6886a1ab0
3 changed files with 21 additions and 3 deletions

View File

@ -91,7 +91,7 @@ module ActiveSupport
begin
yield
rescue => error
error_reporter.report(error, handled: false, source: source)
error_reporter&.report(error, handled: false, source: source)
raise
ensure
instance.complete!
@ -108,7 +108,7 @@ module ActiveSupport
end
end
def self.error_reporter
def self.error_reporter # :nodoc:
ActiveSupport.error_reporter
end

View File

@ -68,8 +68,15 @@ module ActiveSupport
# Run the supplied block as a work unit, reloading code as needed
def self.wrap(**kwargs)
return yield if active?
executor.wrap(**kwargs) do
super
instance = run!
begin
yield
ensure
instance.complete!
end
end
end

View File

@ -85,6 +85,17 @@ class ReloaderTest < ActiveSupport::TestCase
assert_equal [:before_unload, :unload, :after_unload, :body], called
end
def test_report_errors_once
reports = ErrorCollector.record do
assert_raises RuntimeError do
reloader.wrap do
raise "Oops"
end
end
end
assert_equal 1, reports.size
end
private
def new_reloader(&check)
Class.new(ActiveSupport::Reloader).tap do |r|