puppetlabs/puppet · error · ArgumentError
Argument to 'return_type' must be a String reference to a Pu
Error message
Argument to 'return_type' must be a String reference to a Puppet Data Type. Got %{type_class} What it means
return_type declares what a function returns. Its argument must be a String reference to a Puppet data type (parsed later) or an already-built PAnyType instance. Anything else, such as a Ruby class or a Symbol, raises this ArgumentError at definition time.
Source
Thrown at lib/puppet/functions.rb:525
# 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 type
required_block_param(*type_and_name)
@block_type = Puppet::Pops::Types::TypeFactory.optional(@block_type)
end
# Defines the return type. Defaults to 'Any'
# @param [String] type a reference to a Puppet Data Type
#
# @api public
def return_type(type)
unless type.is_a?(String) || type.is_a?(Puppet::Pops::Types::PAnyType)
raise ArgumentError, _("Argument to 'return_type' must be a String reference to a Puppet Data Type. Got %{type_class}") % { type_class: type.class }
end
@return_type = type
end
private
# @api private
def internal_param(type, name, repeat = false)
raise ArgumentError, _('Parameters cannot be added after a block parameter') unless @block_type.nil?
raise ArgumentError, _('Parameters cannot be added after a repeated parameter') if @max == :default
if name.is_a?(String)
raise ArgumentError, _("Parameter name argument must be a Symbol. Got %{name_class}") % { name_class: name.class }
end
if type.is_a?(String) || type.is_a?(Puppet::Pops::Types::PAnyType)
@types << typeView on GitHub (pinned to e227c27540)
Solutions
- Quote the type: return_type 'String' or return_type 'Optional[Array[Integer]]'.
- Or pass a constructed type object, for example Puppet::Pops::Types::TypeFactory.string.
- Check for stray colons after refactors; Symbols fail the check.
Example fix
# before return_type Integer return_type :String # after return_type 'Integer' return_type 'Optional[Array[Integer]]'
Defensive patterns
Strategy: type-guard
Type guard
return_type_guard = ->(t) { t.is_a?(String) || t.is_a?(Puppet::Pops::Types::PAnyType) }
raise ArgumentError, 'quote return types: "String"' unless return_type_guard.call('String') Prevention
- Always quote return types: return_type 'String'.
- Pass PAnyType instances from TypeFactory when types are built programmatically.
- Reject Symbols and Ruby classes in the return-type position during review.
When it happens
Trigger: return_type Integer (a Ruby Class) or return_type :String (a Symbol) inside a create_function block. Only return_type 'Integer' or a Puppet::Pops::Types instance is accepted.
Common situations: Muscle memory from Ruby method signatures; refactoring from param-style strings to Ruby constants and over-applying it to return_type.
Related errors
- Parameter 'type' must be a String reference to a Puppet Data
- Function Load Error for function '%{function_name}': %{messa
- A required parameter cannot be added after an optional param
- block_param accepts max 2 arguments (type, name), got %{size
- Expected PCallableType or PVariantType thereof, got %{type_c
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/54c5ef594f29d082.
Report an issue: GitHub.