]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Small changes. Added better error checking etc ...
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Sat, 23 Apr 2011 17:11:08 +0000 (18:11 +0100)
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Sat, 23 Apr 2011 17:11:08 +0000 (18:11 +0100)
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
collect_indices.rb
join.rb

index 65abfcee63bd5d7acc6e74006fdd8d7e8fc8b46b..e96c3e9c8f96b16cdbd6a9ce424592e582658459 100644 (file)
@@ -10,7 +10,12 @@ module Puppet::Parser::Functions
     raise(Puppet::ParseError, "Wrong number of arguments " +
       "given (#{arguments.size} for 2)") if arguments.size < 2
 
-    array   = arguments.shift
+    array = arguments.shift
+
+    if not array.is_a?(Array)
+      raise(Puppet::ParseError, 'Requires an array to work with')
+    end
+
     indices = *arguments # Get them all ... Pokemon ...
 
     if not indices or indices.empty?
diff --git a/join.rb b/join.rb
index b616e056fc8a7cdee9fe2a359a5f8070aa0a77f5..4522d23697f4b57a91bf729c08b0150f0a75bd6d 100644 (file)
--- a/join.rb
+++ b/join.rb
@@ -7,11 +7,26 @@ module Puppet::Parser::Functions
     EOS
   ) do |arguments|
 
+    # Technically we support three arguments but only first two are mandatory ....
+    raise(Puppet::ParseError, "Wrong number of arguments " +
+      "given (#{arguments.size} for 2)") if arguments.size < 2
+
     array = arguments[0]
 
+    if not array.is_a?(Array)
+      raise(Puppet::ParseError, 'Requires an array to work with')
+    end
+
     suffix = arguments[1]
     prefix = arguments[2]
 
+    raise(Puppet::ParseError, 'You must provide suffix ' +
+      'to join array elements with') if suffix.empty?
+
+    if prefix and prefix.empty?
+      raise(Puppet::ParseError, 'You must provide prefix to add to join')
+    end
+
     if prefix and not prefix.empty?
       result = prefix + array.join(suffix + prefix)
     else