{"record":{"id":"fa89536d39f31c12","repo":"puppetlabs/puppet","slug":"unable-to-parse-message-fa8953","errorCode":null,"errorMessage":"Unable to parse %{message}","messagePattern":"Unable to parse %(.+?)","errorType":"exception","errorClass":"Puppet::DataBinding::LookupError","httpStatus":null,"severity":"error","filePath":"lib/puppet/functions/yaml_data.rb","lineNumber":38,"sourceCode":"    param 'Puppet::LookupContext', :context\n  end\n\n  def yaml_data(options, context)\n    path = options['path']\n    context.cached_file_data(path) do |content|\n      data = Puppet::Util::Yaml.safe_load(content, [Symbol], path)\n      if data.is_a?(Hash)\n        Puppet::Pops::Lookup::HieraConfig.symkeys_to_string(data)\n      else\n        msg = _(\"%{path}: file does not contain a valid yaml hash\" % { path: path })\n        raise Puppet::DataBinding::LookupError, msg if Puppet[:strict] == :error && data != false\n\n        Puppet.warning(msg)\n        {}\n      end\n    rescue Puppet::Util::Yaml::YamlLoadError => ex\n      # YamlLoadErrors include the absolute path to the file, so no need to add that\n      raise Puppet::DataBinding::LookupError, _(\"Unable to parse %{message}\") % { message: ex.message }\n    end\n  end\n\n  def missing_path(options, context)\n    \"one of 'path', 'paths' 'glob', 'globs' or 'mapped_paths' must be declared in hiera.yaml when using this data_hash function\"\n  end\nend\n","sourceCodeStart":20,"sourceCodeEnd":46,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/functions/yaml_data.rb#L20-L46","documentation":"While resolving Hiera data through the 'yaml_data' function, Puppet::Util::Yaml.safe_load raised a YamlLoadError (unparsable YAML, forbidden alias, or a disallowed Ruby object/tag). The function rescues it and re-raises as Puppet::DataBinding::LookupError prefixed 'Unable to parse', aborting the catalog compile. Unlike the not-a-hash case, this raises regardless of strict mode.","triggerScenarios":"A matched YAML file contains anchors/aliases (&base / *ref), which safe_load rejects; tab characters used for indentation; unbalanced quotes or brackets; binary or corrupted file content; a wrong file pulled in by a glob or mapped_paths entry.","commonSituations":"Trying to DRY hiera files with YAML anchors (works in some external tools, rejected by safe_load); copy-pasting rendered ERB/EPP output that introduces tabs; a file truncated mid-deploy; symlinking non-hiera YAML into the datadir.","solutions":["Reproduce the parse locally: ruby -ryaml -e \"YAML.safe_load(File.read('file.yaml'), aliases: false)\" — the YamlLoadError message embedded in 'Unable to parse %' includes the file and line.","Remove YAML anchors and aliases; inline the repeated values.","Replace tabs with spaces and fix indentation/quote errors reported at the given line.","Use 'puppet lookup --explain' to confirm which matched path is the culprit when globs are involved."],"exampleFix":"# before (safe_load rejects aliases)\nbase: &base\n  server: 'puppet.example.com'\nprod:\n  <<: *base\n\n# after (inline the data)\nbase:\n  server: 'puppet.example.com'\nprod:\n  server: 'puppet.example.com'","handlingStrategy":"validation","validationCode":"require 'yaml'\n\ndef parseable?(path)\n  YAML.safe_load(File.read(path), permitted_classes: [Symbol], aliases: false)\n  true\nrescue Psych::SyntaxError, StandardError => e\n  warn \"#{path}: #{e.message}\"\n  false\nend\n\nexit 1 unless Dir['data/**/*.yaml'].all? { |f| parseable?(f) }","typeGuard":null,"tryCatchPattern":"begin\n  value = Puppet.lookup(:hiera).lookup(key, scope)\nrescue Puppet::DataBinding::LookupError => e\n  # e.message starts with 'Unable to parse' and includes file/line\n  raise if ENV['STRICT_HIERA']\n  default_value\nend","preventionTips":["Never use YAML anchors/aliases in hiera data files; safe_load always rejects them.","Editor: force spaces (never tabs) for YAML files.","Add a YAML syntax check to pre-commit hooks for the datadir."],"tags":["puppet","hiera","yaml","safe-load","data-binding"],"backgroundTag":"yaml-parse-error","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}