diff options
author | Henrik Lindberg <henrik.lindberg@cloudsmith.com> | 2014-09-30 14:07:00 -0700 |
---|---|---|
committer | Andrew Parker <andy@puppetlabs.com> | 2014-10-06 14:55:34 -0700 |
commit | 13faa18fc5b774c540f5a368dc4ed165d061827d (patch) | |
tree | 69dfef4e99b8b608203cd0ece20bb22a52ff7828 | |
parent | e19552a098258daab0894befcb8d7ef73a60e715 (diff) | |
download | puppet-13faa18fc5b774c540f5a368dc4ed165d061827d.tar.gz |
(PUP-3364) Improve the error message for numeric resource titles
This improves the error message when a numeric resource title is
used in a resource reference, or when a numeric attribute name is
referenced. The message used to be too generic, and used internal
Ruby types instead of puppet types in the message string.
-rw-r--r-- | lib/puppet/pops/evaluator/access_operator.rb | 14 | ||||
-rw-r--r-- | lib/puppet/pops/evaluator/runtime3_support.rb | 1 | ||||
-rw-r--r-- | spec/unit/pops/evaluator/evaluating_parser_spec.rb | 10 |
3 files changed, 9 insertions, 16 deletions
diff --git a/lib/puppet/pops/evaluator/access_operator.rb b/lib/puppet/pops/evaluator/access_operator.rb index e849a2c4e..623fb1a60 100644 --- a/lib/puppet/pops/evaluator/access_operator.rb +++ b/lib/puppet/pops/evaluator/access_operator.rb @@ -232,7 +232,7 @@ class Puppet::Pops::Evaluator::AccessOperator when :default 'Default' else - actual.class.name + Puppet::Pops::Types::TypeCalculator.generalize!(Puppet::Pops::Types::TypeCalculator.infer(actual)).to_s end end @@ -462,7 +462,7 @@ class Puppet::Pops::Evaluator::AccessOperator else # blame given left expression if it defined the type, else the first given key expression blame = o.type_name.nil? ? @semantic.keys[0] : @semantic.left_expr - fail(Puppet::Pops::Issues::ILLEGAL_RESOURCE_SPECIALIZATION, blame, {:actual => type_name.class}) + fail(Puppet::Pops::Issues::ILLEGAL_RESOURCE_SPECIALIZATION, blame, {:actual => bad_key_type_name(type_name)}) end # type name must conform @@ -508,18 +508,10 @@ class Puppet::Pops::Evaluator::AccessOperator keys = [:no_title] if keys.size < 1 # if there was only a type_name and it was consumed result = keys.each_with_index.map do |t, i| unless t.is_a?(String) || t == :no_title - type_to_report = case t - when nil - 'Undef' - when :default - 'Default' - else - t.class.name - end index = keys_orig_size != keys.size ? i+1 : i fail(Puppet::Pops::Issues::BAD_TYPE_SPECIALIZATION, @semantic.keys[index], { :type => o, - :message => "Cannot use #{type_to_report} where String is expected" + :message => "Cannot use #{bad_key_type_name(t)} where a resource title String is expected" }) end diff --git a/lib/puppet/pops/evaluator/runtime3_support.rb b/lib/puppet/pops/evaluator/runtime3_support.rb index 127c7d6f5..83b7adb32 100644 --- a/lib/puppet/pops/evaluator/runtime3_support.rb +++ b/lib/puppet/pops/evaluator/runtime3_support.rb @@ -394,6 +394,7 @@ module Puppet::Pops::Evaluator::Runtime3Support # Returns true, if the given name is the name of a resource parameter. # def is_parameter_of_resource?(scope, resource, name) + return false unless name.is_a?(String) resource.valid_parameter?(name) end diff --git a/spec/unit/pops/evaluator/evaluating_parser_spec.rb b/spec/unit/pops/evaluator/evaluating_parser_spec.rb index 5e80e4076..2a3988c56 100644 --- a/spec/unit/pops/evaluator/evaluating_parser_spec.rb +++ b/spec/unit/pops/evaluator/evaluating_parser_spec.rb @@ -680,12 +680,12 @@ describe 'Puppet::Pops::Evaluator::EvaluatorImpl' do "'abc'[x]" => "The value 'x' cannot be converted to Numeric", "'abc'[1.0]" => "A String[] cannot use Float where Integer is expected", "'abc'[1,2,3]" => "String supports [] with one or two arguments. Got 3", - "Resource[0]" => 'First argument to Resource[] must be a resource type or a String. Got Fixnum', - "Resource[a, 0]" => 'Error creating type specialization of a Resource-Type, Cannot use Fixnum where String is expected', - "File[0]" => 'Error creating type specialization of a File-Type, Cannot use Fixnum where String is expected', + "Resource[0]" => 'First argument to Resource[] must be a resource type or a String. Got Integer', + "Resource[a, 0]" => 'Error creating type specialization of a Resource-Type, Cannot use Integer where a resource title String is expected', + "File[0]" => 'Error creating type specialization of a File-Type, Cannot use Integer where a resource title String is expected', "String[a]" => "A Type's size constraint arguments must be a single Integer type, or 1-2 integers (or default). Got a String", - "Pattern[0]" => 'Error creating type specialization of a Pattern-Type, Cannot use Fixnum where String or Regexp or Pattern-Type or Regexp-Type is expected', - "Regexp[0]" => 'Error creating type specialization of a Regexp-Type, Cannot use Fixnum where String or Regexp is expected', + "Pattern[0]" => 'Error creating type specialization of a Pattern-Type, Cannot use Integer where String or Regexp or Pattern-Type or Regexp-Type is expected', + "Regexp[0]" => 'Error creating type specialization of a Regexp-Type, Cannot use Integer where String or Regexp is expected', "Regexp[a,b]" => 'A Regexp-Type[] accepts 1 argument. Got 2', "true[0]" => "Operator '[]' is not applicable to a Boolean", "1[0]" => "Operator '[]' is not applicable to an Integer", |