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

Type error in function parameter is reported on wrong parameter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 4.8.1
    • Fix Version/s: PUP 4.9.0
    • Component/s: Language
    • Labels:
      None
    • Environment:

      Puppet Server 4.7.2, Debian

    • Template:
    • Team:
      Puppet Developer Experience
    • Story Points:
      1
    • Sprint:
      PDE 2017-01-11
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      When a type mismatch occurred when performing automatic parameter type checking it could end up being reported for the wrong parameter.
    • QA Risk Assessment:
      No Action
    • QA Risk Assessment Reason:
      covered by unit tests

      Description

      While writing a new puppet language function I ran into a wrong type error.

      The error

       Error while evaluating a Function Call, 'saltnetwork::iptables::is_builtin_chain' parameter 'table' expects a match for SaltNetwork::IPTables::Table = Enum['filter', 'mangle', 'nat', 'raw', 'security'], got 'filter'
      

      occurred when calling

      saltnetwork::iptables::is_builtin_chain('filter', 'INPUT')
      

      with the function in this form (parameter type of the second parameter is wrong and does not match INPUT, see type aliases below). I would expect an error about the second parameter, not the perfectly fine first one.

      function saltnetwork::iptables::is_builtin_chain(
          SaltNetwork::IPTables::Table $table
        , SaltNetwork::IPTables::Custom_Chain_Name $chain
        ) {
       
        $chain in saltnetwork::iptables::builtin_chains_for_table($table)
      }
      

      with the type aliases

      type SaltNetwork::IPTables::Table = Enum['filter','nat','mangle','raw','security']
      

      type SaltNetwork::IPTables::Custom_Chain_Name = Pattern[/^(?!(PREROUTING|INPUT|FORWARD|OUTPUT|POSTROUTING))[a-zA-Z][a-zA-Z0-9-]{0,31}$/]
      

      and the function used in the body

      function saltnetwork::iptables::builtin_chains_for_table(
          SaltNetwork::IPTables::Table $table
        ) {
        case($table) {
        "filter": {
          ['INPUT','FORWARD','OUTPUT']
        }
        "nat": {
          ['PREROUTING','INPUT','OUTPUT','POSTROUTING']
        }
        "mangle": {
          ['PREROUTING','INPUT','FORWARD','OUTPUT','POSTROUTING']
        }
        "raw": {
          ['PREROUTING','OUTPUT']
        }
        "security": {
          ['INPUT','FORWARD','OUTPUT']
        }
        default: {
          fail("Unknown table ${table}, you need to adjust SaltNetwork::IPTables::Table and this function")
        }
        }
      }
      

        Attachments

          Activity

            jsd-sla-details-panel

              People

              • Assignee:
                Unassigned
                Reporter:
                mhoermann Matthias Hörmann
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: