puppetlabs/puppet · error · ArgumentError
block_param accepts max 2 arguments (type, name), got %{size
Error message
block_param accepts max 2 arguments (type, name), got %{size}. What it means
block_param accepts zero, one, or two arguments: (), (name), or (type, name). Any third argument raises this ArgumentError at definition time. The case/size dispatch in the ParameterDsl has no branch above 2.
Source
Thrown at lib/puppet/functions.rb:488
# Defines one required block parameter that may appear last. If type and name is missing the
# default type is "Callable", and the name is "block". If only one
# parameter is given, then that is the name and the type is "Callable".
#
# @api public
def block_param(*type_and_name)
case type_and_name.size
when 0
type = @all_callables
name = :block
when 1
type = @all_callables
name = type_and_name[0]
when 2
type, name = type_and_name
type = Puppet::Pops::Types::TypeParser.singleton.parse(type, loader) unless type.is_a?(Puppet::Pops::Types::PAnyType)
else
raise ArgumentError, _("block_param accepts max 2 arguments (type, name), got %{size}.") % { size: type_and_name.size }
end
unless Puppet::Pops::Types::TypeCalculator.is_kind_of_callable?(type, false)
raise ArgumentError, _("Expected PCallableType or PVariantType thereof, got %{type_class}") % { type_class: type.class }
end
unless name.is_a?(Symbol)
raise ArgumentError, _("Expected block_param name to be a Symbol, got %{name_class}") % { name_class: name.class }
end
if @block_type.nil?
@block_type = type
@block_name = name
else
raise ArgumentError, _('Attempt to redefine block')
end
end
alias required_block_param block_paramView on GitHub (pinned to e227c27540)
Solutions
- Pass at most two arguments: a type reference and a Symbol name.
- For defaults, use block_param with no arguments: the default is type Callable and name :block.
- For an optional block with a default of nil in the method, use optional_block_param instead of extra arguments.
Example fix
# before block_param 'Callable', :block, 'unused' # after block_param 'Callable', :block # or simply: block_param -> Callable, :block
Defensive patterns
Strategy: validation
Validate before calling
# CI grep: block_param called with three or more comma-separated arguments ! grep -rnE "block_param[[:space:]]+[^,]+,[^,]+," lib/
Prevention
- Remember the three legal shapes: block_param, block_param :name, block_param 'Type', :name.
- Block defaults are expressed with optional_block_param, not with extra arguments.
- Delete leftover arguments when converting a param line into block_param.
When it happens
Trigger: block_param 'Callable', :block, 'extra' inside a dispatch block; usually a copy-paste of a param line into block_param, or a mistaken belief that block_param takes a default value argument.
Common situations: Editing existing dispatch blocks; converting a param declaration into a block declaration and leaving extra arguments behind.
Related errors
- Attempt to redefine block
- Function Load Error for function '%{function_name}': %{messa
- A required parameter cannot be added after an optional param
- Expected PCallableType or PVariantType thereof, got %{type_c
- Expected block_param name to be a Symbol, got %{name_class}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/de26913b325c96f8.
Report an issue: GitHub.