]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Ruby 2.0 introduces IPAddr::InvalidAddressError
authorWill Farrington <wfarr@github.com>
Thu, 23 May 2013 00:19:03 +0000 (17:19 -0700)
committerWill Farrington <wfarr@github.com>
Thu, 23 May 2013 00:21:38 +0000 (17:21 -0700)
lib/puppet/parser/functions/validate_ipv4_address.rb
lib/puppet/parser/functions/validate_ipv6_address.rb

index 2de145433ca94e8aba4ab80abb8e790ea55a0181..fc02748e816243576cdeadb32b20693f2981342b 100644 (file)
@@ -18,6 +18,13 @@ module Puppet::Parser::Functions
     ENDHEREDOC
   ) do |args|
 
+    require "ipaddr"
+    rescuable_exceptions = [ ArgumentError ]
+
+    if defined?(IPAddr::InvalidAddressError)
+      rescuable_exceptions << IPAddr::InvalidAddressError
+    end
+
     unless args.length > 0 then
       raise Puppet::ParseError, ("validate_ipv4_address(): wrong number of arguments (#{args.length}; must be > 0)")
     end
@@ -31,7 +38,7 @@ module Puppet::Parser::Functions
         unless IPAddr.new(arg).ipv4?
           raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv4 address."
         end
-      rescue ArgumentError
+      rescue *rescuable_exceptions
         raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv4 address."
       end
     end
index d270b4d13ca8a6158517268166704a4ad70a0c4b..b0f2558df77d87f7599b49795c0c6a42db5e14a2 100644 (file)
@@ -19,6 +19,13 @@ module Puppet::Parser::Functions
     ENDHEREDOC
   ) do |args|
 
+    require "ipaddr"
+    rescuable_exceptions = [ ArgumentError ]
+
+    if defined?(IPAddr::InvalidAddressError)
+      rescuable_exceptions << IPAddr::InvalidAddressError
+    end
+
     unless args.length > 0 then
       raise Puppet::ParseError, ("validate_ipv6_address(): wrong number of arguments (#{args.length}; must be > 0)")
     end
@@ -32,7 +39,7 @@ module Puppet::Parser::Functions
         unless IPAddr.new(arg).ipv6?
           raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv6 address."
         end
-      rescue ArgumentError
+      rescue *rescuable_exceptions
         raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv6 address."
       end
     end