{"record":{"id":"59971ada0da9fb23","repo":"puppetlabs/puppet","slug":"a-required-repeated-parameter-cannot-be-added-afte","errorCode":null,"errorMessage":"A required repeated parameter cannot be added after an optional parameter","messagePattern":"A required repeated parameter cannot be added after an optional parameter","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/functions.rb","lineNumber":465,"sourceCode":"    def repeated_param(type, name)\n      internal_param(type, name, true)\n      @max = :default\n    end\n    alias optional_repeated_param repeated_param\n\n    # Defines a repeated positional parameter with _type_ and _name_ that may occur 1 to \"infinite\" number of times.\n    # It may only appear last or just before a block parameter.\n    #\n    # @param type [String] The type specification for the parameter.\n    # @param name [Symbol] The name of the parameter. This is primarily used\n    #   for error message output and does not have to match an implementation\n    #   method parameter.\n    # @return [Void]\n    #\n    # @api public\n    def required_repeated_param(type, name)\n      internal_param(type, name, true)\n      raise ArgumentError, _('A required repeated parameter cannot be added after an optional parameter') if @min != @max\n\n      @min += 1\n      @max = :default\n    end\n\n    # Defines one required block parameter that may appear last. If type and name is missing the\n    # default type is \"Callable\", and the name is \"block\". If only one\n    # parameter is given, then that is the name and the type is \"Callable\".\n    #\n    # @api public\n    def block_param(*type_and_name)\n      case type_and_name.size\n      when 0\n        type = @all_callables\n        name = :block\n      when 1\n        type = @all_callables\n        name = type_and_name[0]","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/functions.rb#L447-L483","documentation":"required_repeated_param declares a 1..N positional parameter. Like param, it is rejected when an optional parameter was already declared (@min != @max), because a mandatory argument cannot follow an optional one. The repeated parameter may only appear last, or just before a block parameter.","triggerScenarios":"dispatch :m do optional_param 'String', :b; required_repeated_param 'String', :rest end. The mandatory repeated parameter after the optional :b raises at definition time.","commonSituations":"Converting a trailing optional parameter list into a variadic capture while an older optional_param stays in place; signature growth over time.","solutions":["Change the trailing capture to optional_repeated_param if the values may be absent (0..N is legal after an optional).","Or make every preceding parameter required (param) so nothing optional precedes the repeated one.","Alternatively split into two dispatch blocks: one for the optional tail, one for the variadic shape."],"exampleFix":"# before\n dispatch :run do\n   optional_param 'String', :prefix\n   required_repeated_param 'String', :rest   # raises\n end\n\n# after: use the optional repeated form after an optional parameter\n dispatch :run do\n   optional_param 'String', :prefix\n   optional_repeated_param 'String', :rest\n end","handlingStrategy":"validation","validationCode":"# CI grep: required_repeated_param must not follow an optional_param in one dispatch\n! grep -Pzo 'dispatch[^}]*optional_param[^}]*\\n[^}]*required_repeated_param' lib/puppet/functions/**/*.rb","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After an optional_param, only optional_repeated_param and block params are legal.","Convert trailing variadics to optional_repeated_param when earlier args stay optional.","Keep dispatch blocks short; long blocks make ordering mistakes easy."],"tags":["puppet","functions","dispatch","parameter-order","variadic"],"backgroundTag":"parameter-order-invalid","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}