puppetlabs/puppet · error · ArgumentError
Parsing of 'type "%{assignment_string}"' failed with message
Error message
Parsing of 'type "%{assignment_string}"' failed with message: <%{message}>.
Called from <%{ruby_file_location}> What it means
The local_types DSL collects type aliases for a function. Each type call parses the string 'type <assignment>' with the Pops parser; a parse failure raises this ArgumentError, embedding the parser message and the Ruby file and line that made the call (via caller(1,1)). This is a definition-time error in the function's Ruby source.
Source
Thrown at lib/puppet/functions.rb:635
# in string form without the leading 'type' keyword.
# Calls to local_type must be made before the first parameter definition or an error will
# be raised.
#
# @param assignment_string [String] a string on the form 'AliasType = ExistingType'
# @api public
#
def type(assignment_string)
# Get location to use in case of error - this produces ruby filename and where call to 'type' occurred
# but strips off the rest of the internal "where" as it is not meaningful to user.
#
rb_location = caller(1, 1).first
begin
result = parser.parse_string("type #{assignment_string}", nil)
rescue StandardError => e
rb_location = rb_location.gsub(/:in.*$/, '')
# Create a meaningful location for parse errors - show both what went wrong with the parsing
# and in which ruby file it was found.
raise ArgumentError, _("Parsing of 'type \"%{assignment_string}\"' failed with message: <%{message}>.\n" \
"Called from <%{ruby_file_location}>") % {
assignment_string: assignment_string,
message: e.message,
ruby_file_location: rb_location
}
end
unless result.body.is_a?(Puppet::Pops::Model::TypeAlias)
rb_location = rb_location.gsub(/:in.*$/, '')
raise ArgumentError, _("Expected a type alias assignment on the form 'AliasType = T', got '%{assignment_string}'.\n" \
"Called from <%{ruby_file_location}>") % {
assignment_string: assignment_string,
ruby_file_location: rb_location
}
end
@local_types << result.body
end
end
View on GitHub (pinned to e227c27540)
Solutions
- Read the embedded parse message; it pinpoints the syntax problem in the assignment string.
- Use the exact form 'AliasName = TypeReference', for example 'MyList = Array[String]'.
- Test the string standalone: Puppet::Pops::Parser::Parser.new.parse_string('type MyList = Array[String]').
- Keep one alias per type call instead of packing several assignments together.
Example fix
# before
local_types { type 'MyList = Array[' }
# after
local_types { type 'MyList = Array[String]' } Defensive patterns
Strategy: validation
Validate before calling
# Validate alias assignment strings in CI exactly as local_types will parse them
parser = Puppet::Pops::Parser::Parser.new
['MyList = Array[String]', 'MyMap = Hash[String, Integer]'].each do |s|
parser.parse_string("type #{s}")
end Prevention
- Write aliases in the exact form 'Name = Type' with balanced brackets.
- One alias per type call.
- Run the parser over all alias strings in CI so syntax errors never reach load time.
When it happens
Trigger: local_types { type 'MyList = Array[' } inside a create_function block: the assignment string has a syntax error, so parser.parse_string raises and the wrapper adds the Ruby location.
Common situations: Unbalanced brackets or a stray character in alias assignments; writing an expression instead of an assignment; typos that break the Puppet language grammar rather than just naming an unknown type.
Related errors
- Expected a type alias assignment on the form 'AliasType = T'
- The parameter '$#{name}' is invalid: #{e.message}
- Function Load Error for function '%{function_name}': %{messa
- Functions must be based on Puppet::Pops::Functions::Function
- Function Creation Error, cannot create a default dispatcher
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/3971fe90fe955737.
Report an issue: GitHub.