{"record":{"id":"5caf66c673c72310","repo":"puppetlabs/puppet","slug":"function-lookup-did-not-find-a-value-for-the-nam","errorCode":null,"errorMessage":"Function lookup() did not find a value for the name '%{name}'","messagePattern":"Function lookup\\(\\) did not find a value for the name '%(.+?)'","errorType":"exception","errorClass":"Puppet::DataBinding::LookupError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/lookup.rb","lineNumber":93,"sourceCode":"      names = names.map { |n| \"'#{n}'\" }.join(', ')\n    end\n    \"Lookup of #{names}\"\n  end\n\n  # @api private\n  def self.search_and_merge(name, lookup_invocation, merge, apl = true)\n    answer = lookup_invocation.lookup_adapter.lookup(name, lookup_invocation, merge)\n    lookup_invocation.emit_debug_info(\"Automatic Parameter Lookup of '#{name}'\") if apl && Puppet[:debug]\n    answer\n  end\n\n  def self.assert_type(subject, type, value)\n    type ? Types::TypeAsserter.assert_instance_of(subject, type, value) : value\n  end\n  private_class_method :assert_type\n\n  def self.fail_lookup(names)\n    raise Puppet::DataBinding::LookupError,\n          n_(\"Function lookup() did not find a value for the name '%{name}'\",\n             \"Function lookup() did not find a value for any of the names [%{name_list}]\", names.size) % { name: names[0], name_list: names.map { |n| \"'#{n}'\" }.join(', ') }\n  end\n  private_class_method :fail_lookup\nend\nend\n\nrequire_relative 'lookup/lookup_adapter'\nrequire_relative 'lookup/key_recorder'\n","sourceCodeStart":75,"sourceCodeEnd":103,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/lookup.rb#L75-L103","documentation":"Puppet::Pops::Lookup.fail_lookup is the terminal failure of the lookup() function (and automatic parameter lookup) when no value was found for the key in any data source and no default was accepted. It raises Puppet::DataBinding::LookupError with a singular or plural message (n_) depending on whether one name or a list of names was requested. This is the classic 'Hiera key not found' error of Puppet 4.9+/Hiera 5.","triggerScenarios":"lookup('myapp::port') where no hierarchy layer contains that key and no default_value/default_value_hash option is given; automatic parameter lookup for a class parameter that has no default in the class signature and no matching data key; lookup(['a','b']) missing both names.","commonSituations":"Key typo or wrong casing; hiera.yaml hierarchy paths pointing to files that do not exist or lack the key; per-node data file missing; forgetting a default; scope interpolation in hiera.yaml producing an unexpected key; environment mismatch so the wrong hierarchy is used.","solutions":["Add the key to a data file that the active hierarchy actually consults (`puppet lookup --explain myapp::port` shows which files were searched and why they missed).","Give the caller an out: lookup('myapp::port', String, 'default') or a default_value option; in APL, add a default to the class parameter.","Check spelling/casing of the key and any %{...} interpolation in hiera.yaml datadir/hierarchy — a bad interpolation silently redirects the search.","Confirm you are in the environment you think (environment=... on the node / lookup invocation), since data is environment-specific."],"exampleFix":"# before\nclass myapp (\n  $port,\n) { }\nlookup('myapp::port')\n\n# after\nclass myapp (\n  $port = 8080,\n) { }\nlookup('myapp::port', Integer, 8080)","handlingStrategy":"try-catch","validationCode":"# Pre-check a key before relying on it (same machinery, no exception)\nfound = Puppet::Pops::Lookup.lookup('myapp::port', nil, nil, false, nil, :hash, invocation) rescue nil\n# or from a manifest/template, probe without failing:\n#   $has = lookup('myapp::port', Integer) { |err| undef }  # block form suppresses the raise","typeGuard":null,"tryCatchPattern":"begin\n  $value = lookup('myapp::port')\nrescue Puppet::DataBinding::LookupError => e\n  warning(\"lookup miss: ${e.message}\")\n  $value = 8080  # safe default\nend","preventionTips":["Always pass a default when a key is legitimately optional: lookup('k', Type, default) or the 'default_value' option.","Give every APL-consumed class parameter a default in its signature.","Use `puppet lookup --explain <key> --node <node>` to verify each key resolves before rolling out.","Lint hierarchy: every path in hiera.yaml should exist (or use the 'path' vs 'glob' options deliberately)."],"tags":["puppet","hiera","lookup","data-binding","key-not-found"],"backgroundTag":"hiera-lookup-key-not-found","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}