{"record":{"id":"d1219739e426fe57","repo":"puppetlabs/puppet","slug":"invalid-data-type-in-lookup-options-for-key-key","errorCode":null,"errorMessage":"Invalid data type in lookup_options for key '%{key}' could not parse '%{source}', error: '%{msg}","messagePattern":"Invalid data type in lookup_options for key '%(.+?)' could not parse '%(.+?)', error: '%(.+?)","errorType":"exception","errorClass":"Puppet::DataBinding::LookupError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/lookup/lookup_adapter.rb","lineNumber":108,"sourceCode":"  #\n  # @param key [String] The key to lookup\n  # @param lookup_options [Hash] a hash of options\n  # @param lookup_invocation [Invocation] the lookup invocation\n  # @param the_lookup [Lambda] zero arg lambda that performs the lookup of a value\n  # @return [Object] the looked up value, or converted value if there was conversion\n  # @throw :no_such_key when the object is not found (if thrown by `the_lookup`)\n  #\n  def convert_result(key, lookup_options, lookup_invocation, the_lookup)\n    result = the_lookup.call\n    convert_to = lookup_options[CONVERT_TO]\n    return result if convert_to.nil?\n\n    convert_to = convert_to.is_a?(Array) ? convert_to : [convert_to]\n    if convert_to[0].is_a?(String)\n      begin\n        convert_to[0] = Puppet::Pops::Types::TypeParser.singleton.parse(convert_to[0])\n      rescue StandardError => e\n        raise Puppet::DataBinding::LookupError,\n              _(\"Invalid data type in lookup_options for key '%{key}' could not parse '%{source}', error: '%{msg}\") %\n              { key: key, source: convert_to[0], msg: e.message }\n      end\n    end\n    begin\n      result = lookup_invocation.scope.call_function(NEW, [convert_to[0], result, *convert_to[1..]])\n      # TRANSLATORS 'lookup_options', 'convert_to' and args_string variable should not be translated,\n      args_string = Puppet::Pops::Types::StringConverter.singleton.convert(convert_to)\n      lookup_invocation.report_text { _(\"Applying convert_to lookup_option with arguments %{args}\") % { args: args_string } }\n    rescue StandardError => e\n      raise Puppet::DataBinding::LookupError,\n            _(\"The convert_to lookup_option for key '%{key}' raised error: %{msg}\") %\n            { key: key, msg: e.message }\n    end\n    result\n  end\n\n  def lookup_global(key, lookup_invocation, merge_strategy)","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/lookup/lookup_adapter.rb#L90-L126","documentation":"In LookupAdapter#convert_result, when a key has a lookup_options entry with a 'convert_to' option whose first element is a String, that string is parsed by Types::TypeParser to get a Puppet type. If parsing raises (malformed type expression), it is wrapped into Puppet::DataBinding::LookupError 'Invalid data type in lookup_options...' naming the key, the offending source string, and the parser error. This validates the convert_to type string before it is ever used to call the new() function.","triggerScenarios":"Data file: `lookup_options: { 'myapp::port': { 'convert_to': 'Integer[' } }` — unterstrained brackets, unknown type name ('Intger'), bad syntax ('Array[String'), or a non-type expression ('8080'). The failure occurs at lookup time of myapp::port, not at config load.","commonSituations":"Typos in long Struct[...] / Optional[...] type strings; YAML quoting mistakes that mangle brackets; copy-paste from docs leaving placeholders; assuming Ruby type syntax works ('Hash<String,Integer>' must be 'Hash[String, Integer]').","solutions":["Fix the type expression in the lookup_options entry to valid Puppet type syntax — the parser message in %{msg} pinpoints the syntax problem.","Validate expressions quickly: `puppet lookup --explain myapp::port` or test the string with TypeParser in a script.","Keep complex types in a type alias (types/mytype.pp) and reference the alias by name in convert_to where supported by your data design."],"exampleFix":"# before: data/common.yaml\nlookup_options:\n  myapp::port:\n    convert_to: 'Integer['\n\n# after\nlookup_options:\n  myapp::port:\n    convert_to: 'Integer[0, 65535]'","handlingStrategy":"validation","validationCode":"# Validate every convert_to type string parses before deploy\nrequire 'puppet'\nrequire 'puppet/pops/types/type_parser'\n\nDir['**/data/**/*.yaml'].each do |f|\n  (YAML.load_file(f)['lookup_options'] || {}).each do |key, opts|\n    ct = opts.is_a?(Hash) ? opts['convert_to'] : nil\n    next unless ct.is_a?(String)\n    begin\n      Puppet::Pops::Types::TypeParser.singleton.parse(ct)\n    rescue StandardError => e\n      abort \"#{f}: lookup_options[#{key}] convert_to '#{ct}' does not parse: #{e.message}\"\n    end\n  end\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["CI-validate every convert_to string with TypeParser (cheap and exact).","Use canonical Puppet type syntax: 'Integer[0,100]', 'Array[String]', 'Optional[String]', 'Struct[{...}]'.","Prefer short, well-known types in convert_to; keep complex types in type aliases."],"tags":["puppet","hiera","lookup-options","convert-to","type-parser"],"backgroundTag":"hiera-lookup-options-invalid-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}