Skip to content

Commit ae51457

Browse files
committed
Raise an ArgumentError when Rails.error.report is passed something that is not an Exception
1 parent 5a6037e commit ae51457

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

activesupport/lib/active_support/error_reporter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def set_context(...)
209209
#
210210
def report(error, handled: true, severity: handled ? :warning : :error, context: {}, source: DEFAULT_SOURCE)
211211
return if error.instance_variable_defined?(:@__rails_error_reported)
212+
raise ArgumentError, "Reported error must be an Exception, got: #{error.inspect}" unless error.is_a?(Exception)
213+
212214
ensure_backtrace(error)
213215

214216
unless SEVERITIES.include?(severity)

activesupport/test/error_reporter_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,20 @@ class ErrorReporterTest < ActiveSupport::TestCase
270270
end
271271
end
272272

273+
test "report raises if passed an argument that is not an Exception" do
274+
error = assert_raises ArgumentError do
275+
@reporter.report(Object.new)
276+
end
277+
assert_includes error.message, "Reported error must be an Exception"
278+
end
279+
280+
test "report raises if passed a String" do
281+
error = assert_raises ArgumentError do
282+
@reporter.report("An error message")
283+
end
284+
assert_includes error.message, "Reported error must be an Exception"
285+
end
286+
273287
test "report errors only once" do
274288
assert_difference -> { @subscriber.events.size }, +1 do
275289
@reporter.report(@error, handled: false)

0 commit comments

Comments
 (0)