]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Updated error check and reporting. Also we now return empty
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Mon, 25 Apr 2011 01:02:00 +0000 (02:02 +0100)
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Mon, 25 Apr 2011 01:02:00 +0000 (02:02 +0100)
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 <krzysztof.wilczynski@linux.com>
fact.rb

diff --git a/fact.rb b/fact.rb
index 95213cc6adaba5fc835bbf7976e05397723063ff..2c22f60c40084f21f9ce3ea83bd9b8cb4c2e51d3 100644 (file)
--- 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