{"record":{"id":"8de0dee3e1fddca4","repo":"puppetlabs/puppet","slug":"could-not-intern-from-format-err","errorCode":null,"errorMessage":"Could not intern from %{format}: %{err}","messagePattern":"Could not intern from %(.+?): %(.+?)","errorType":"exception","errorClass":"Puppet::Network::FormatHandler::FormatError","httpStatus":null,"severity":"error","filePath":"lib/puppet/network/format_support.rb","lineNumber":17,"sourceCode":"# frozen_string_literal: true\n\nrequire_relative '../../puppet/network/format_handler'\n\n# Provides network serialization support when included\n# @api public\nmodule Puppet::Network::FormatSupport\n  def self.included(klass)\n    klass.extend(ClassMethods)\n  end\n\n  module ClassMethods\n    def convert_from(format, data)\n      get_format(format).intern(self, data)\n    rescue => err\n      # TRANSLATORS \"intern\" is a function name and should not be translated\n      raise Puppet::Network::FormatHandler::FormatError, _(\"Could not intern from %{format}: %{err}\") % { format: format, err: err }, err.backtrace\n    end\n\n    def convert_from_multiple(format, data)\n      get_format(format).intern_multiple(self, data)\n    rescue => err\n      # TRANSLATORS \"intern_multiple\" is a function name and should not be translated\n      raise Puppet::Network::FormatHandler::FormatError, _(\"Could not intern_multiple from %{format}: %{err}\") % { format: format, err: err }, err.backtrace\n    end\n\n    def render_multiple(format, instances)\n      get_format(format).render_multiple(instances)\n    rescue => err\n      # TRANSLATORS \"render_multiple\" is a function name and should not be translated\n      raise Puppet::Network::FormatHandler::FormatError, _(\"Could not render_multiple to %{format}: %{err}\") % { format: format, err: err }, err.backtrace\n    end\n\n    def default_format\n      supported_formats[0]","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/network/format_support.rb#L1-L35","documentation":"FormatSupport's convert_from deserializes one instance through a format and wraps every failure — bad JSON/YAML syntax, safe_load rejections, or a NotImplementedError from a format the class does not implement — into a single FormatError that names the format and embeds the original error message and backtrace. It means 'deserializing this payload as :format failed'; the %{err} part is the real diagnosis.","triggerScenarios":"Klass.convert_from(:json, '{ not json') on any FormatSupport model (facts, catalogs, reports, custom models); convert_from(:yaml, payload) where the YAML carries classes outside the allowed list; convert_from(:msgpack, ...) when msgpack support is not loaded.","commonSituations":"REST clients posting bodies whose Content-Type does not match the bytes; corrupted YAML caches in an agent's state directory; producer/consumer Puppet version skew; custom report processors fed malformed input.","solutions":["Read the embedded %{err} first — JSON parse error vs YamlLoadError vs NotImplementedError each point to a different fix (payload, safe_load allow-list, or missing format support).","Pre-validate the payload with Puppet::Util::Json.load or Puppet::Util::Yaml.safe_load to get the precise error before entering convert_from.","If the bytes come from local cache, delete the stale file(s) in the state/yaml directories and let Puppet regenerate them.","Align formats and versions between producer and consumer (both sides json, same Puppet major)."],"exampleFix":"# before\nfacts = Puppet::Node::Facts.convert_from(:json, request_body) # FormatError on bad JSON\n\n# after — pre-parse, fail with a precise error\nbegin\n  Puppet::Util::Json.load(request_body)\nrescue Puppet::Util::Json::ParseError => e\n  raise ArgumentError, \"invalid facts payload: #{e.message}\"\nend\nfacts = Puppet::Node::Facts.convert_from(:json, request_body)","handlingStrategy":"try-catch","validationCode":"case format\nwhen :json\n  Puppet::Util::Json.load(text) # raises ParseError with location info\nwhen :yaml\n  Puppet::Util::Yaml.safe_load(text, []) # raises YamlLoadError early\nend","typeGuard":null,"tryCatchPattern":"begin\n  obj = Klass.convert_from(fmt, text)\nrescue Puppet::Network::FormatHandler::FormatError => e\n  log.warn(\"rejected #{fmt} payload: #{e.message}\")\n  raise\nend","preventionTips":["Match Content-Type to the actual payload bytes before parsing.","Pre-parse with Puppet::Util::Json / Puppet::Util::Yaml for precise failures.","Never hand-edit Puppet's cached YAML; delete and regenerate instead.","Keep both endpoints on compatible Puppet major versions."],"tags":["puppet","ruby","serialization","json","yaml","deserialization"],"backgroundTag":"deserialization-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}