Skip to content

Commit d350ee4

Browse files
authored
Merge pull request #651 from HelenCampbell/deprecationUpdate
Addition of logging with file and line numbers
2 parents 8da9579 + b63862f commit d350ee4

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Function to print deprecation warnings, Logs a warning once for a given key. The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method It is affected by the puppet setting 'strict', which can be set to :error (outputs as an error message), :off (no message / error is displayed) and :warning (default, outputs a warning) *Type*: String, String.
2-
#
32

43
Puppet::Functions.create_function(:deprecation) do
54
dispatch :deprecation do
@@ -9,13 +8,16 @@
98

109
def deprecation(key, message)
1110
# depending on configuration setting of strict
11+
caller_infos = caller.first.split(":")
1212
case Puppet.settings[:strict]
1313
when :off
1414
# do nothing
1515
when :error
16-
fail("deprecation. #{key}. #{message}")
16+
err_message = "#{message} : #{caller_infos[0]} : #{caller_infos[1]}"
17+
fail("deprecation. #{key}. #{err_message}")
1718
else
18-
Puppet.deprecation_warning(message, key)
19+
err_message = "#{message} : #{caller_infos[0]} : #{caller_infos[1]}"
20+
Puppet.deprecation_warning(err_message, key)
1921
end
2022
end
2123
end

lib/puppet/functions/validate_legacy.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ def validate_legacy(target_type, previous_validation, value, *prev_args)
2828
Puppet.warn("Accepting previously invalid value for target_type '#{target_type}'")
2929
end
3030
else
31+
caller_infos = caller.first.split(":")
3132
inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(value)
32-
error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch(previous_validation, target_type, inferred_type)
33+
message = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch(previous_validation, target_type, inferred_type)
34+
error_msg = "#{message} : #{caller_infos[0]} : #{caller_infos[1]}"
3335
if previous_validation(previous_validation, value, *prev_args)
3436
Puppet.warn(error_msg)
3537
else

lib/puppet/parser/functions/deprecation.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ module Puppet::Parser::Functions
1111
message = arguments[1]
1212

1313
if ENV['STDLIB_LOG_DEPRECATIONS'] == "true"
14-
warning("deprecation. #{key}. #{message}")
14+
caller_infos = caller.first.split(":")
15+
err_message = "#{message} : #{caller_infos[0]} : #{caller_infos[1]}"
16+
warning("deprecation. #{key}. #{err_message}")
1517
end
1618
end
1719
end

0 commit comments

Comments
 (0)