{"record":{"id":"f023df31e345cf63","repo":"puppetlabs/puppet","slug":"could-not-read-json-data-for-name-key-det","errorCode":null,"errorMessage":"Could not read JSON data for %{name} %{key}: %{detail}","messagePattern":"Could not read JSON data for %(.+?) %(.+?): %(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/indirector/json.rb","lineNumber":65,"sourceCode":"    base = data_dir\n    File.join(base, self.class.indirection_name.to_s, name.to_s + ext)\n  end\n\n  private\n\n  def data_dir\n    Puppet.run_mode.server? ? Puppet[:server_datadir] : Puppet[:client_datadir]\n  end\n\n  def load_json_from_file(file, key)\n    json = nil\n\n    begin\n      json = Puppet::FileSystem.read(file, :encoding => Encoding::BINARY)\n    rescue Errno::ENOENT\n      return nil\n    rescue => detail\n      raise Puppet::Error, _(\"Could not read JSON data for %{name} %{key}: %{detail}\") % { name: indirection.name, key: key, detail: detail }, detail.backtrace\n    end\n\n    begin\n      from_json(json)\n    rescue => detail\n      raise Puppet::Error, _(\"Could not parse JSON data for %{name} %{key}: %{detail}\") % { name: indirection.name, key: key, detail: detail }, detail.backtrace\n    end\n  end\n\n  def from_json(text)\n    model.convert_from('json', text.force_encoding(Encoding::UTF_8))\n  end\n\n  def to_json(object)\n    object.render('json')\n  end\nend\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/indirector/json.rb#L47-L83","documentation":"load_json_from_file reads the stored .json file in binary mode; Errno::ENOENT returns nil (a cache miss), but any other failure - EACCES, EISDIR, EMFILE, EIO - is wrapped as Puppet::Error 'Could not read JSON data for <indirection> <key>: <detail>' with the original backtrace.","triggerScenarios":"find/search on a json-backed indirection when the stored file exists but is unreadable by the service user, the path has been replaced by a directory, or the process ran out of file descriptors.","commonSituations":"Datadir files left 600/root after a restore or manual copy; backup jobs recreating paths as directories; long-running masters hitting fd limits; SELinux context changes.","solutions":["Read the <detail> suffix to identify the errno, then reproduce as the service user (sudo -u puppet cat <file>).","chown/chmod the file and its parent directory to the puppet service user.","Remove or rename the directory sitting at the file path so Puppet can recreate the file.","Raise ulimit / fix fd leaks if the detail says 'too many open files'."],"exampleFix":"# before\n# Could not read JSON data for node node1.example.com: Permission denied @ rb_sysopen\n\n# after\nchown puppet:puppet /opt/puppetlabs/server/data/puppet/node/node1.example.com.json\nchmod 660 /opt/puppetlabs/server/data/puppet/node/node1.example.com.json","handlingStrategy":"try-catch","validationCode":"file = store_path_for(key)\nraise ArgumentError, 'unreadable store file' unless File.readable?(file)\nindirection.find(key)","typeGuard":null,"tryCatchPattern":"begin\n  Puppet::Node.indirection.find(key)\nrescue Puppet::Error => e\n  Puppet.err(e.message)\n  nil\nend","preventionTips":["Keep datadir ownership uniform under the service user.","Monitor server logs for EACCES on datadir paths.","Exclude datadirs from backup tooling that recreates files as directories."],"tags":["puppet","json-store","filesystem","permissions","read-failure"],"backgroundTag":"file-permission-denied","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}