From 61936fdeaaadb25e83ccb766e6b9ac872527a50d Mon Sep 17 00:00:00 2001 From: Krzysztof Wilczynski Date: Mon, 25 Apr 2011 02:02:00 +0100 Subject: Updated error check and reporting. Also we now return empty string value i.e. "" instead of raising an exception when a particular fact is not present. We also make use of strinterp() explicitly to evaluate arguments passed to the function. Signed-off-by: Krzysztof Wilczynski --- fact.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fact.rb b/fact.rb index 95213cc..2c22f60 100644 --- a/fact.rb +++ b/fact.rb @@ -44,17 +44,25 @@ partitions define given above. EOS ) do |arguments| - raise(Puppet::ParseError, "Wrong number of arguments " + + raise(Puppet::ParseError, "fact(): Wrong number of arguments " + "given (#{arguments.size} for 1)") if arguments.size < 1 fact = arguments[0] - raise(Puppet::ParseError, 'You must provide fact name') if fact.empty? + raise(Puppet::ParseError, 'fact(): You must provide ' + + 'fact name') if fact.empty? + fact = strinterp(fact) # Evaluate any interpolated variable names ... result = lookupvar(fact) # Get the value of interest from Facter ... if not result or result.empty? - raise(Puppet::ParseError, "Unable to retrieve fact `#{fact}'") + # + # Now this is a funny one ... Puppet does not have a concept of + # returning neither undef nor nil back for use within the Puppet DSL + # and empty string is as closest to actual undef as you we can get + # at this point in time ... + # + result = '' end return result -- cgit v1.2.3