puppetlabs/puppet · error · ArgumentError
Expected block_param name to be a Symbol, got %{name_class}
Error message
Expected block_param name to be a Symbol, got %{name_class} What it means
The name given to block_param must be a Symbol. With one argument that argument is taken as the name; with two, the second is the name. Passing a String (for example 'block') fails the Symbol check and raises this ArgumentError at definition time.
Source
Thrown at lib/puppet/functions.rb:496
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_param
# Defines one optional block parameter that may appear last. If type or name is missing the
# defaults are "any callable", and the name is "block". The implementor of the dispatch target
# must use block = nil when it is optional (or an error is raised when the call is made).
#
# @api public
def optional_block_param(*type_and_name)
# same as required, only wrap the result in an optional typeView on GitHub (pinned to e227c27540)
Solutions
- Write the name as a Symbol: block_param 'Callable', :block.
- With a single argument, pass the Symbol name only: block_param :block.
- Adopt the convention that every name in a dispatch block (param names included) is written with a leading colon.
Example fix
# before block_param 'Callable', 'block' block_param 'block' # after block_param 'Callable', :block block_param :block
Defensive patterns
Strategy: type-guard
Type guard
# Every DSL name argument must be a Symbol
name_guard = ->(name) { name.is_a?(Symbol) }
raise ArgumentError, 'pass :block not "block"' unless name_guard.call(:block) Prevention
- Write names with a leading colon everywhere in dispatch blocks.
- Call to_sym on generated names before passing them.
- Treat quoted names in a dispatch block as a smell to fix on sight.
When it happens
Trigger: block_param 'block' (a single String is treated as the name), or block_param 'Callable', 'block'. Both leave name as a String at the is_a?(Symbol) check.
Common situations: Copy-paste of param declarations where strings are common; forgetting that DSL names in dispatch blocks are Symbols.
Related errors
- Expected PCallableType or PVariantType thereof, got %{type_c
- Parameter name argument must be a Symbol. Got %{name_class}
- block_param accepts max 2 arguments (type, name), got %{size
- Attempt to redefine block
- Argument to 'return_type' must be a String reference to a Pu
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/b07bbb805dba620d.
Report an issue: GitHub.