Ruby 2.0 introduces IPAddr::InvalidAddressError

This commit is contained in:
Will Farrington 2013-05-22 17:19:03 -07:00
parent cf37a128a0
commit 9a41f07e3b
2 changed files with 16 additions and 2 deletions

View file

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

View file

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