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.weight

View on GitHub (pinned to e227c27540)

Solutions

  1. Define the multiple renderer on the model (def self.to_json_multiple(list) ...).
  2. Short-circuit empty arrays before calling render_multiple.
  3. Fix the element-level failure named in %{err} — usually inside to_data_hash.
  4. 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

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


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