{"record":{"id":"8745b85e9cc8d73e","repo":"puppetlabs/puppet","slug":"could-not-find-data-item-key-in-any-hiera-data","errorCode":null,"errorMessage":"Could not find data item %{key} in any Hiera data file and no default supplied","messagePattern":"Could not find data item %(.+?) in any Hiera data file and no default supplied","errorType":"exception","errorClass":"Puppet::ParseError","httpStatus":null,"severity":"error","filePath":"lib/hiera_puppet.rb","lineNumber":16,"sourceCode":"# frozen_string_literal: true\n\nPuppet.features.hiera?\nrequire 'hiera/scope'\nrequire_relative 'puppet'\n\nmodule HieraPuppet\n  module_function\n\n  def lookup(key, default, scope, override, resolution_type)\n    scope = Hiera::Scope.new(scope)\n\n    answer = hiera.lookup(key, default, scope, override, resolution_type)\n\n    if answer.nil?\n      raise Puppet::ParseError, _(\"Could not find data item %{key} in any Hiera data file and no default supplied\") % { key: key }\n    end\n\n    answer\n  end\n\n  def parse_args(args)\n    # Functions called from Puppet manifests like this:\n    #\n    #   hiera(\"foo\", \"bar\")\n    #\n    # Are invoked internally after combining the positional arguments into a\n    # single array:\n    #\n    #   func = function_hiera\n    #   func([\"foo\", \"bar\"])\n    #\n    # Functions called from templates preserve the positional arguments:\n    #","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/hiera_puppet.rb#L1-L34","documentation":"HieraPuppet.lookup raises Puppet::ParseError when hiera.lookup returns nil and no default was passed: the key had no value at any level of the hierarchy. The legacy hiera() function is a fail-if-miss exact lookup by design, so a miss without a default is fatal at compile time.","triggerScenarios":"Calling hiera('mykey') in a manifest or scope.function_hiera(['mykey']) in a template when no hierarchy level defines mykey; also when the hierarchy or datadir is misconfigured so every lookup misses.","commonSituations":"Missing or typo'd key in hiera data; hiera.yaml hierarchy paths not matching the actual file layout; an eyaml/encrypted backend failing silently so nothing matches; code migrated from another site that assumed a default existed.","solutions":["Supply an explicit default: hiera('mykey', 'sane-default')","Add the key to the hierarchy level that should own it, then verify with: puppet lookup --explain mykey","Fix the hierarchy in hiera.yaml (paths, datadir, backends) if every key misses","Prefer the modern lookup() function with an explicit default_value over the deprecated hiera()"],"exampleFix":"# before\n$port = hiera('myapp::port')  # ParseError when key absent everywhere\n\n# after\n$port = lookup('myapp::port', Integer, 'first', 8080)","handlingStrategy":"fallback","validationCode":"answer = hiera.lookup(key, :__missing__, scope, override, resolution_type)\nif answer == :__missing__\n  answer = computed_default # or raise a domain-specific error\nend","typeGuard":null,"tryCatchPattern":"begin\n  value = hiera('mykey')\nrescue Puppet::ParseError\n  value = 'sane-default' # or lookup('mykey', 'sane-default') from the start\nend","preventionTips":["Default to lookup('key', default) syntax so a miss is never fatal","Verify keys exist with 'puppet lookup --explain key' before shipping profiles that depend on them","Keep hierarchy paths in hiera.yaml tested in CI so misses are caught early"],"tags":["hiera","lookup","data","puppet"],"backgroundTag":"hiera-key-not-found","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}