Skip to content

Commit c6886a1

Browse files
committed
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: rails#46100
1 parent 2d36ebc commit c6886a1

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

activesupport/lib/active_support/execution_wrapper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def self.wrap(source: "application.active_support")
9191
begin
9292
yield
9393
rescue => error
94-
error_reporter.report(error, handled: false, source: source)
94+
error_reporter&.report(error, handled: false, source: source)
9595
raise
9696
ensure
9797
instance.complete!
@@ -108,7 +108,7 @@ def self.perform # :nodoc:
108108
end
109109
end
110110

111-
def self.error_reporter
111+
def self.error_reporter # :nodoc:
112112
ActiveSupport.error_reporter
113113
end
114114

activesupport/lib/active_support/reloader.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,15 @@ def self.run!(reset: false) # :nodoc:
6868

6969
# Run the supplied block as a work unit, reloading code as needed
7070
def self.wrap(**kwargs)
71+
return yield if active?
72+
7173
executor.wrap(**kwargs) do
72-
super
74+
instance = run!
75+
begin
76+
yield
77+
ensure
78+
instance.complete!
79+
end
7380
end
7481
end
7582

activesupport/test/reloader_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ def test_class_unload_block
8585
assert_equal [:before_unload, :unload, :after_unload, :body], called
8686
end
8787

88+
def test_report_errors_once
89+
reports = ErrorCollector.record do
90+
assert_raises RuntimeError do
91+
reloader.wrap do
92+
raise "Oops"
93+
end
94+
end
95+
end
96+
assert_equal 1, reports.size
97+
end
98+
8899
private
89100
def new_reloader(&check)
90101
Class.new(ActiveSupport::Reloader).tap do |r|

0 commit comments

Comments
 (0)