Skip to content

Commit 8f8fd4f

Browse files
author
Helen Campbell
committed
Call site display for deprecation warnings
1 parent dcef77a commit 8f8fd4f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/puppet/functions/deprecation.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
end
99

1010
def deprecation(key, message)
11+
stacktrace = Puppet::Pops::PuppetStack.stacktrace()
12+
output_message = "${message} at ${stacktrace[0][0]}:${stacktrace[0]:[1]}"
1113
# depending on configuration setting of strict
1214
case Puppet.settings[:strict]
1315
when :off
1416
# do nothing
1517
when :error
16-
fail("deprecation. #{key}. #{message}")
18+
fail("deprecation. #{key}. #{output_message}")
1719
else
1820
unless ENV['STDLIB_LOG_DEPRECATIONS'] == 'false'
19-
Puppet.deprecation_warning(message, key)
21+
Puppet.deprecation_warning(output_message, key)
2022
end
2123
end
2224
end

spec/acceptance/deprecation_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
end
3232

3333
it "should show the error message" do
34-
expect(@result.stderr).to match(/deprecation. key. message/)
34+
expect(@result.stderr).to match(/deprecation. key. \$\{message\}/)
3535
end
3636

3737
describe file("#{test_file}") do
@@ -53,7 +53,7 @@
5353
end
5454

5555
it "should show the error message" do
56-
expect(@result.stderr).to match(/Warning: message/)
56+
expect(@result.stderr).to match(/Warning: \$\{message\} at \$\{stacktrace\[0\]\[0\]\}:\$\{stacktrace\[0\]:\[1\]\}/)
5757
end
5858

5959
describe file("#{test_file}") do

0 commit comments

Comments
 (0)