Skip to content

Commit 8f9c561

Browse files
authored
Merge pull request rails#50054 from Shopify/deprecator-thread-each-caller
Formally deprecate passing `caller` to `Deprecation#warn`
2 parents 7fe794c + 37b0c60 commit 8f9c561

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

activesupport/lib/active_support/deprecation/reporting.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ def extract_callstack(callstack)
151151
end
152152

153153
def _extract_callstack(callstack)
154-
warn "Please pass `caller_locations` to the deprecation API" if $VERBOSE
154+
ActiveSupport.deprecator.warn(<<~MESSAGE)
155+
Passing the result of `caller` to ActiveSupport::Deprecation#warn is deprecated and will be removed in Rails 7.2.
156+
157+
Please pass the result of `caller_locations` instead.
158+
MESSAGE
159+
155160
offending_line = callstack.find { |line| !ignored_callstack?(line) } || callstack.first
156161

157162
if offending_line

activesupport/test/deprecation_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def setup
3939
end
4040
end
4141

42+
test "passing callstack as `caller` is deprecated" do
43+
assert_deprecated(/Passing the result of `caller` to ActiveSupport::Deprecation#warn/, ActiveSupport.deprecator) do
44+
assert_deprecated(@deprecator) do
45+
@deprecator.warn("Yo dawg!", caller)
46+
end
47+
end
48+
end
49+
4250
test "assert_deprecated is deprecated without a deprecator" do
4351
assert_deprecated(ActiveSupport.deprecator) do
4452
assert_deprecated do

0 commit comments

Comments
 (0)