puppetlabs/puppet · error · NotImplementedError

%{klass} does not respond to %{method}; can not render multi

Error message

%{klass} does not respond to %{method}; can not render multiple instances to %{mime}

What it means

Format#render_multiple(instances) assumes a homogeneous list and dispatches to the class-level render_multiple_method (e.g. to_json_multiple) on instances[0]'s class. When that class method is absent, NotImplementedError is raised. Adjacent pitfalls: an empty list makes instances[0] nil (NoMethodError), and mixed classes silently use the first element's renderer. FormatSupport.render_multiple wraps this as FormatError 'Could not render_multiple to ...'.

Source

Thrown at lib/puppet/network/format.rb:78

    raise NotImplementedError, "#{klass} does not respond to #{intern_multiple_method}; can not intern multiple instances from #{mime}"
  end

  def mime=(mime)
    @mime = mime.to_s.downcase
  end

  def render(instance)
    return instance.send(render_method) if instance.respond_to?(render_method)

    raise NotImplementedError, "#{instance.class} does not respond to #{render_method}; can not render instances to #{mime}"
  end

  def render_multiple(instances)
    # This method implicitly assumes that all instances are of the same type.
    return instances[0].class.send(render_multiple_method, instances) if instances[0].class.respond_to?(render_multiple_method)

    raise NotImplementedError, _("%{klass} does not respond to %{method}; can not render multiple instances to %{mime}") %
                               { klass: instances[0].class, method: render_multiple_method, mime: mime }
  end

  def required_methods_present?(klass)
    [:intern_method, :intern_multiple_method, :render_multiple_method].each do |name|
      return false unless required_method_present?(name, klass, :class)
    end

    return false unless required_method_present?(:render_method, klass, :instance)

    true
  end

  def supported?(klass)
    suitable? and required_methods_present?(klass)
  end

  def to_s

View on GitHub (pinned to e227c27540)

Solutions

  1. Define the class-level multiple renderer, e.g. def self.to_json_multiple(list) = Puppet::Util::Json.dump(list.map(&:to_data_hash)) end.
  2. Guard empty lists before calling render_multiple (dispatch reads instances[0]).
  3. Pick the format from supported_formats so the full method set exists.
  4. For custom formats, provide a render_multiple proc in Puppet::Network::FormatHandler.create.

Example fix

# before
class Widget
  include Puppet::Network::FormatSupport
  def to_data_hash = { 'id' => @id }
end
Widget.render_multiple(:json, widgets) # Widget has no to_json_multiple

# after
class Widget
  def self.to_json_multiple(list) = Puppet::Util::Json.dump(list.map(&:to_data_hash))
end
Defensive patterns

Strategy: fallback

Validate before calling

return '[]' if instances.empty?
raise ArgumentError, 'mixed classes in list' unless instances.map(&:class).uniq.size == 1
fmt_name = Widget.supported_formats.include?(:json) ? :json : Widget.default_format
Widget.render_multiple(fmt_name, instances)

Type guard

def renders_multiple?(klass, format_name)
  fmt = Puppet::Network::FormatHandler.format(format_name)
  !fmt.nil? && klass.respond_to?(fmt.render_multiple_method)
end

Try / catch

begin
  Widget.render_multiple(:json, instances)
rescue Puppet::Network::FormatHandler::FormatError, NotImplementedError
  # degrade to per-instance rendering when the multiple renderer is missing
  '[' + instances.map { |i| i.render(:json) }.join(',') + ']'
end

Prevention

When it happens

Trigger: Klass.render_multiple(:json, instances) where the class lacks to_json_multiple — e.g. a custom model with only per-object rendering — or a list endpoint handing arrays of a class that never declared the multiple renderer.

Common situations: Search/list REST handlers serializing arrays of indirected models; custom faces returning arrays; formats registered with only a single render method.

Related errors


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