{"record":{"id":"3971fe90fe955737","repo":"puppetlabs/puppet","slug":"parsing-of-type-assignment-string-failed-wi","errorCode":null,"errorMessage":"Parsing of 'type \"%{assignment_string}\"' failed with message: <%{message}>.\nCalled from <%{ruby_file_location}>","messagePattern":"Parsing of 'type \"%(.+?)\"' failed with message: <%(.+?)>\\.\nCalled from <%(.+?)>","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/functions.rb","lineNumber":635,"sourceCode":"    # in string form without the leading 'type' keyword.\n    # Calls to local_type must be made before the first parameter definition or an error will\n    # be raised.\n    #\n    # @param assignment_string [String] a string on the form 'AliasType = ExistingType'\n    # @api public\n    #\n    def type(assignment_string)\n      # Get location to use in case of error - this produces ruby filename and where call to 'type' occurred\n      # but strips off the rest of the internal \"where\" as it is not meaningful to user.\n      #\n      rb_location = caller(1, 1).first\n      begin\n        result = parser.parse_string(\"type #{assignment_string}\", nil)\n      rescue StandardError => e\n        rb_location = rb_location.gsub(/:in.*$/, '')\n        # Create a meaningful location for parse errors - show both what went wrong with the parsing\n        # and in which ruby file it was found.\n        raise ArgumentError, _(\"Parsing of 'type \\\"%{assignment_string}\\\"' failed with message: <%{message}>.\\n\" \\\n                               \"Called from <%{ruby_file_location}>\") % {\n                                 assignment_string: assignment_string,\n                                 message: e.message,\n                                 ruby_file_location: rb_location\n                               }\n      end\n      unless result.body.is_a?(Puppet::Pops::Model::TypeAlias)\n        rb_location = rb_location.gsub(/:in.*$/, '')\n        raise ArgumentError, _(\"Expected a type alias assignment on the form 'AliasType = T', got '%{assignment_string}'.\\n\" \\\n                               \"Called from <%{ruby_file_location}>\") % {\n                                 assignment_string: assignment_string,\n                                 ruby_file_location: rb_location\n                               }\n      end\n      @local_types << result.body\n    end\n  end\n","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/functions.rb#L617-L653","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\n local_types { type 'MyList = Array[' }\n\n# after\n local_types { type 'MyList = Array[String]' }","handlingStrategy":"validation","validationCode":"# Validate alias assignment strings in CI exactly as local_types will parse them\nparser = Puppet::Pops::Parser::Parser.new\n['MyList = Array[String]', 'MyMap = Hash[String, Integer]'].each do |s|\n  parser.parse_string(\"type #{s}\")\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["puppet","functions","local-types","type-alias","parse-error"],"backgroundTag":"type-string-parse-error","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}