diff options
author | Adrien Thebo <git@somethingsinistral.net> | 2013-08-12 11:27:56 -0700 |
---|---|---|
committer | Adrien Thebo <git@somethingsinistral.net> | 2013-08-12 12:55:46 -0700 |
commit | 6df05cbc2d6d4d85774de7ca16f1fc557f69516d (patch) | |
tree | 38994c54241a1e6503da6f086b0c63463b706bc8 /lib/puppet/parser | |
parent | e63715ddaf7c2e5a742ce29e5e159b6031918963 (diff) | |
download | puppet-stdlib-6df05cbc2d6d4d85774de7ca16f1fc557f69516d.tar.gz puppet-stdlib-6df05cbc2d6d4d85774de7ca16f1fc557f69516d.tar.bz2 |
(maint) clean up validate_slength argument validation
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r-- | lib/puppet/parser/functions/validate_slength.rb | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/puppet/parser/functions/validate_slength.rb b/lib/puppet/parser/functions/validate_slength.rb index 68054b8..83c7ed0 100644 --- a/lib/puppet/parser/functions/validate_slength.rb +++ b/lib/puppet/parser/functions/validate_slength.rb @@ -30,24 +30,26 @@ module Puppet::Parser::Functions end begin - max_length = max_length.to_i - rescue NoMethodError => e - raise Puppet::ParseError, "validate_slength(): Expected second argument to be a positive Numeric, got a #{max_length.class}" + max_length = Integer(max_length) + raise ArgumentError if max_length <= 0 + rescue ArgumentError, TypeError + raise Puppet::ParseError, "validate_slength(): Expected second argument to be a positive Numeric, got #{max_length}:#{max_length.class}" end - unless args.length == 2 + if min_length begin min_length = Integer(min_length) - rescue StandardError => e - raise Puppet::ParseError, "validate_slength(): Expected third argument to be unset or a positive Numeric, got a #{min_length.class}" + raise ArgumentError if min_length < 0 + rescue ArgumentError, TypeError + raise Puppet::ParseError, "validate_slength(): Expected third argument to be unset or a positive Numeric, got #{min_length}:#{min_length.class}" end else min_length = 0 end - raise Puppet::ParseError, "validate_slength(): please pass a positive number as max_length" unless max_length > 0 - raise Puppet::ParseError, "validate_slength(): please pass a positive number as min_length" unless min_length >= 0 - raise Puppet::ParseError, "validate_slength(): please pass a min length that is smaller than the maximum" unless min_length <= max_length + if min_length > max_length + raise Puppet::ParseError, "validate_slength(): Expected second argument to be larger than third argument" + end case input when String |