{"record":{"id":"653ccc1e9ff9e09d","repo":"puppetlabs/puppet","slug":"attempt-to-redefine-block","errorCode":null,"errorMessage":"Attempt to redefine block","messagePattern":"Attempt to redefine block","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/functions.rb","lineNumber":503,"sourceCode":"        type, name = type_and_name\n        type = Puppet::Pops::Types::TypeParser.singleton.parse(type, loader) unless type.is_a?(Puppet::Pops::Types::PAnyType)\n      else\n        raise ArgumentError, _(\"block_param accepts max 2 arguments (type, name), got %{size}.\") % { size: type_and_name.size }\n      end\n\n      unless Puppet::Pops::Types::TypeCalculator.is_kind_of_callable?(type, false)\n        raise ArgumentError, _(\"Expected PCallableType or PVariantType thereof, got %{type_class}\") % { type_class: type.class }\n      end\n\n      unless name.is_a?(Symbol)\n        raise ArgumentError, _(\"Expected block_param name to be a Symbol, got %{name_class}\") % { name_class: name.class }\n      end\n\n      if @block_type.nil?\n        @block_type = type\n        @block_name = name\n      else\n        raise ArgumentError, _('Attempt to redefine block')\n      end\n    end\n    alias required_block_param block_param\n\n    # Defines one optional block parameter that may appear last. If type or name is missing the\n    # defaults are \"any callable\", and the name is \"block\". The implementor of the dispatch target\n    # must use block = nil when it is optional (or an error is raised when the call is made).\n    #\n    # @api public\n    def optional_block_param(*type_and_name)\n      # same as required, only wrap the result in an optional type\n      required_block_param(*type_and_name)\n      @block_type = Puppet::Pops::Types::TypeFactory.optional(@block_type)\n    end\n\n    # Defines the return type. Defaults to 'Any'\n    # @param [String] type a reference to a Puppet Data Type\n    #","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/functions.rb#L485-L521","documentation":"A dispatch signature may declare at most one block parameter. The first block_param (or optional_block_param, which delegates to it) sets @block_type; any second call finds @block_type non-nil and raises this ArgumentError.","triggerScenarios":"block_param 'Callable', :block followed later in the same dispatch block by optional_block_param 'Callable', :fallback, or by a second block_param with a different name.","commonSituations":"Trying to accept two different blocks (a transformer and an error handler) in one signature; copy-paste of an existing block_param line when adding a new parameter.","solutions":["Keep exactly one block_param or optional_block_param per dispatch block.","If two callbacks are needed, pass the second as a regular param typed 'Callable[...]' and call it with the call() function or a lambda.","Split the signature into two dispatch blocks if the two blocks belong to different call shapes."],"exampleFix":"# before: two block parameters in one dispatch\n dispatch :m do\n   param 'String', :s\n   block_param 'Callable', :block\n   optional_block_param 'Callable', :on_error   # raises: redefine\n end\n\n# after: one block, second callback is a Callable param\n dispatch :m do\n   param 'String', :s\n   param 'Callable', :on_error\n   block_param 'Callable', :block\n end","handlingStrategy":"validation","validationCode":"# CI grep: more than one block-param declaration inside a single dispatch block\n! grep -Pzo 'dispatch[^}]*block_param[^}]*\\n[^}]*(block_param|optional_block_param)' lib/puppet/functions/**/*.rb","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allow exactly one block_param or optional_block_param per dispatch block.","Pass extra callbacks as 'Callable' params, invoked with call().","Never copy a block_param line when adding parameters."],"tags":["puppet","functions","block-param","duplicate","dsl"],"backgroundTag":"duplicate-parameter-definition","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}