puppetlabs/puppet · error · Puppet::Network::FormatHandler::FormatError

Could not intern from %{format}: %{err}

Error message

Could not intern from %{format}: %{err}

What it means

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.

Source

Thrown at lib/puppet/network/format_support.rb:17

# frozen_string_literal: true

require_relative '../../puppet/network/format_handler'

# Provides network serialization support when included
# @api public
module Puppet::Network::FormatSupport
  def self.included(klass)
    klass.extend(ClassMethods)
  end

  module ClassMethods
    def convert_from(format, data)
      get_format(format).intern(self, data)
    rescue => err
      # TRANSLATORS "intern" is a function name and should not be translated
      raise Puppet::Network::FormatHandler::FormatError, _("Could not intern from %{format}: %{err}") % { format: format, err: err }, err.backtrace
    end

    def convert_from_multiple(format, data)
      get_format(format).intern_multiple(self, data)
    rescue => err
      # TRANSLATORS "intern_multiple" is a function name and should not be translated
      raise Puppet::Network::FormatHandler::FormatError, _("Could not intern_multiple from %{format}: %{err}") % { format: format, err: err }, err.backtrace
    end

    def render_multiple(format, instances)
      get_format(format).render_multiple(instances)
    rescue => err
      # TRANSLATORS "render_multiple" is a function name and should not be translated
      raise Puppet::Network::FormatHandler::FormatError, _("Could not render_multiple to %{format}: %{err}") % { format: format, err: err }, err.backtrace
    end

    def default_format
      supported_formats[0]

View on GitHub (pinned to e227c27540)

Solutions

  1. 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).
  2. Pre-validate the payload with Puppet::Util::Json.load or Puppet::Util::Yaml.safe_load to get the precise error before entering convert_from.
  3. If the bytes come from local cache, delete the stale file(s) in the state/yaml directories and let Puppet regenerate them.
  4. Align formats and versions between producer and consumer (both sides json, same Puppet major).

Example fix

# before
facts = Puppet::Node::Facts.convert_from(:json, request_body) # FormatError on bad JSON

# after — pre-parse, fail with a precise error
begin
  Puppet::Util::Json.load(request_body)
rescue Puppet::Util::Json::ParseError => e
  raise ArgumentError, "invalid facts payload: #{e.message}"
end
facts = Puppet::Node::Facts.convert_from(:json, request_body)
Defensive patterns

Strategy: try-catch

Validate before calling

case format
when :json
  Puppet::Util::Json.load(text) # raises ParseError with location info
when :yaml
  Puppet::Util::Yaml.safe_load(text, []) # raises YamlLoadError early
end

Try / catch

begin
  obj = Klass.convert_from(fmt, text)
rescue Puppet::Network::FormatHandler::FormatError => e
  log.warn("rejected #{fmt} payload: #{e.message}")
  raise
end

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/8de0dee3e1fddca4. Report an issue: GitHub.