summaryrefslogtreecommitdiff
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorWill Farrington <wfarr@github.com>2013-05-22 17:19:03 -0700
committerWill Farrington <wfarr@github.com>2013-05-22 17:21:38 -0700
commit9a41f07e3b7f1ad44ac5260814867591f13a9d3e (patch)
tree0903affef7806c13b20042b6312cd0dd1f19e499 /lib/puppet/parser
parentcf37a128a0939a6ba842d735a664b957905cbd87 (diff)
downloadpuppet-stdlib-9a41f07e3b7f1ad44ac5260814867591f13a9d3e.tar.gz
puppet-stdlib-9a41f07e3b7f1ad44ac5260814867591f13a9d3e.tar.bz2
Ruby 2.0 introduces IPAddr::InvalidAddressError
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/functions/validate_ipv4_address.rb9
-rw-r--r--lib/puppet/parser/functions/validate_ipv6_address.rb9
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/puppet/parser/functions/validate_ipv4_address.rb b/lib/puppet/parser/functions/validate_ipv4_address.rb
index 2de1454..fc02748 100644
--- a/lib/puppet/parser/functions/validate_ipv4_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv4_address.rb
@@ -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
diff --git a/lib/puppet/parser/functions/validate_ipv6_address.rb b/lib/puppet/parser/functions/validate_ipv6_address.rb
index d270b4d..b0f2558 100644
--- a/lib/puppet/parser/functions/validate_ipv6_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv6_address.rb
@@ -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