puppetlabs/puppet · error · Puppet::Network::FormatHandler::FormatError
Could not intern_multiple from %{format}: %{err}
Error message
Could not intern_multiple from %{format}: %{err} What it means
convert_from_multiple wraps any exception raised while deserializing a list of instances through format.intern_multiple into a FormatError naming the format and the original error. Typical underlying causes: the payload is not a collection (the YAML format raises its own FormatError which then gets wrapped), one element fails parsing, or the class lacks the intern_multiple method (NotImplementedError wrapped).
Source
Thrown at lib/puppet/network/format_support.rb:24
# @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]
end
def support_format?(name)
Puppet::Network::FormatHandler.format(name).supported?(self)
end
def supported_formatsView on GitHub (pinned to e227c27540)
Solutions
- Make the payload a collection (YAML sequence / JSON array) of per-instance documents or Hashes.
- Pre-parse and shape-check: data = Puppet::Util::Yaml.safe_load(text, []); reject unless data.respond_to?(:collect).
- Fix the producer to serialize arrays when a list is expected.
- Use convert_from for genuine single documents.
Example fix
# before
Widget.convert_from_multiple(:yaml, File.read('widgets.yaml'))
# widgets.yaml contains '--- 42' → wrapped FormatError
# after — widgets.yaml is a sequence
# ---
# - id: 1
# - id: 2
list = Widget.convert_from_multiple(:yaml, File.read('widgets.yaml')) Defensive patterns
Strategy: validation
Validate before calling
data = format == :json ? Puppet::Util::Json.load(text) : Puppet::Util::Yaml.safe_load(text, []) raise ArgumentError, 'expected a collection of instances' unless data.respond_to?(:collect) list = Klass.convert_from_multiple(format, text)
Try / catch
begin list = Klass.convert_from_multiple(fmt, text) rescue Puppet::Network::FormatHandler::FormatError => e # message embeds the real cause: non-collection, parse error, or missing method warn e.message list = [] end
Prevention
- Dump arrays, not scalars, when producers write list payloads.
- Pre-check respond_to?(:collect) on loaded data.
- Validate each element is a Hash before interning.
- Version-lock producers and consumers.
When it happens
Trigger: Klass.convert_from_multiple(:yaml, '--- foo') (scalar document); convert_from_multiple(:json, '[{"a":},]') (malformed element); convert_from_multiple(:json, list) on a class without from_json_multiple.
Common situations: List endpoints receiving single-object payloads by mistake; batch report/fact uploads with one corrupt element; producers writing YAML.dump(obj) where the consumer expects YAML.dump([obj]).
Related errors
- Could not intern from %{format}: %{err}
- Serialized YAML did not contain a valid instance of %{klass}
- Serialized YAML did not contain a collection of instances wh
- Serialized YAML did not contain a valid instance of %{klass}
- #{path}: #{detail.message}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/47dc9d4b99ecb567.
Report an issue: GitHub.