Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-6669

Puppet should return better errors for Enum mismatches

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 4.8.0
    • Component/s: None
    • Labels:
      None
    • Template:
    • Acceptance Criteria:
      Hide

      That a type mismatch between an Enum and a String indicates the value of the String.

      Show
      That a type mismatch between an Enum and a String indicates the value of the String.
    • Story Points:
      1
    • Sprint:
      Language 2016-09-07
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      The error message shown when there is a type mismatch between and Enum data type and a String has been improved to show the value of the string.

      Description

      given the following code:

      define foo (
        Optional[Enum['foo', 'bar']] $x
      ){
        notify { $x: }
      }
      foo { 'lolnope':
        x => 'baz',
      }
      

      Puppet will return this Error:

      Error: Evaluation Error: Error while evaluating a Resource Statement, Foo[lolnope]:
        parameter 'x' expects a match for Enum['bar', 'baz'], got String  at /tmp/foo.pp:6 on node levix
      

      (note the suspicious additional blank)

      my naïve patch:

      diff --git a/lib/puppet/pops/types/type_mismatch_describer.rb b/lib/puppet/pops/types/type_mismatch_describer.rb
      index 98763ad..3f11e96 100644
      --- a/lib/puppet/pops/types/type_mismatch_describer.rb
      +++ b/lib/puppet/pops/types/type_mismatch_describer.rb
      @@ -578,7 +578,7 @@ module Types
               value = param_hash[name]
               value_type = elem.value_type
               if param_hash.include?(name)
      -          result << describe(value_type, TypeCalculator.singleton.infer_set(value).generalize, [ParameterPathElement.new(name)]) unless value_type.instance?(value)
      +          result << describe(value_type, TypeCalculator.singleton.infer_set(value), [ParameterPathElement.new(name)]) unless value_type.instance?(value)
               else
                 result << MissingParameter.new(nil, name) unless elem.key_type.assignable?(PUndefType::DEFAULT) unless missing_ok
               end
      

      works for this case:

      Error: Evaluation Error: Error while evaluating a Resource Statement, Foo[lolnope]:
        parameter 'x' expects a match for Enum['bar', 'baz'], got String 'baz' at /tmp/foo.pp:6 on node levix
      

      but breaks other types — in particular the new Sensitive type.

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  qa qa
                  Reporter:
                  igalic Igor Galić
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: