puppetlabs/puppet · error · Puppet::Network::FormatHandler::FormatError
Could not render_multiple to %{format}: %{err}
Error message
Could not render_multiple to %{format}: %{err} What it means
ClassMethods.render_multiple serializes a list through the format's render_multiple and wraps any failure into FormatError 'Could not render_multiple to %{format}: %{err}'. Common wrapped causes: NotImplementedError because the class lacks the class-level multiple renderer, an exception inside to_data_hash on one element, or an empty list (instances[0] nil → NoMethodError).
Source
Thrown at lib/puppet/network/format_support.rb:31
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_formats
result = format_handler.formats.collect do |f|
format_handler.format(f)
end.find_all do |f|
f.supported?(self)
end.sort do |a, b|
# It's an inverse sort -- higher weight formats go first.
b.weight <=> a.weightView on GitHub (pinned to e227c27540)
Solutions
- Define the multiple renderer on the model (def self.to_json_multiple(list) ...).
- Short-circuit empty arrays before calling render_multiple.
- Fix the element-level failure named in %{err} — usually inside to_data_hash.
- Degrade to per-instance rendering when the list renderer cannot be added.
Example fix
# before
Widget.render_multiple(:json, widgets) # FormatError wrapping NotImplementedError/NoMethodError
# after
return '[]' if widgets.empty?
payload = widgets.map { |w| w.render(:json) }.join(',')
"[#{payload}]" Defensive patterns
Strategy: fallback
Validate before calling
return '[]' if instances.empty? raise ArgumentError, 'mixed classes in list' unless instances.map(&:class).uniq.size == 1
Try / catch
begin
Widget.render_multiple(:json, instances)
rescue Puppet::Network::FormatHandler::FormatError
# degrade to per-instance rendering
'[' + instances.map { |i| i.render(:json) }.join(',') + ']'
end Prevention
- Handle empty lists before the call — dispatch reads instances[0].
- Make to_data_hash total: handle nils explicitly so it never raises mid-list.
- Advertise only formats with complete method sets via supported_formats.
- Test list rendering with empty, single and many elements.
When it happens
Trigger: Klass.render_multiple(:json, instances) with a model missing to_json_multiple; a list whose elements raise inside their serializer; calling it with [] where the dispatch path still dereferences instances[0].
Common situations: Search/list endpoints and custom faces emitting arrays; models that only support single-object rendering; partially populated objects (nil attributes) blowing up to_data_hash mid-list.
Related errors
- #{instance.class} does not respond to #{render_method}; can
- %{klass} does not respond to %{method}; can not render multi
- Could not render to %{format}: %{err}
- #{klass} does not respond to #{intern_multiple_method}; can
- No format matches the given format name or mime-type (%{form
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/9b69de4d64a1fad8.
Report an issue: GitHub.