puppetlabs/puppet · error · NotImplementedError
#{instance.class} does not respond to #{render_method}; can
Error message
#{instance.class} does not respond to #{render_method}; can not render instances to #{mime} What it means
Format#render(instance) serializes one object by sending the format's render_method (to_json, to_yaml, to_msgpack) to the instance. If the instance's class never defines that method, NotImplementedError is raised. Called through FormatSupport#render it is normally wrapped as FormatError 'Could not render to ...', so the raw NotImplementedError means render was invoked on the format object directly.
Source
Thrown at lib/puppet/network/format.rb:71
return klass.send(intern_method, text) if klass.respond_to?(intern_method)
raise NotImplementedError, "#{klass} does not respond to #{intern_method}; can not intern instances from #{mime}"
end
def intern_multiple(klass, text)
return klass.send(intern_multiple_method, text) if klass.respond_to?(intern_multiple_method)
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)
trueView on GitHub (pinned to e227c27540)
Solutions
- Implement the renderer on the model. For FormatSupport classes the cheapest correct fix is defining to_data_hash — FormatSupport derives to_json/to_msgpack from it.
- Switch to a format the class supports: pick from obj.class.supported_formats / default_format instead of a hardcoded name.
- Install and load the optional serialization gem (msgpack) so Puppet registers those renderers for the model.
- Verify pluginsync delivered any custom format code to the node doing the rendering.
Example fix
# before
class Widget
include Puppet::Network::FormatSupport
end
Widget.new.render(:json) # Widget does not respond to to_json
# after
class Widget
include Puppet::Network::FormatSupport
def to_data_hash = { 'id' => @id, 'name' => @name } # FormatSupport builds to_json/to_msgpack on this
end Defensive patterns
Strategy: type-guard
Validate before calling
fmt_name = Widget.supported_formats.include?(:msgpack) ? :msgpack : Widget.default_format payload = Widget.new.render(fmt_name)
Type guard
def renderable?(instance, format_name) fmt = Puppet::Network::FormatHandler.format(format_name) !fmt.nil? && instance.respond_to?(fmt.render_method) end
Try / catch
begin instance.render(:json) rescue Puppet::Network::FormatHandler::FormatError, NotImplementedError => e # message names the class and missing render method — fall back to the default format instance.render(instance.class.default_format) end
Prevention
- Define to_data_hash on every FormatSupport model; the standard renderers hang off it.
- Never pass client-supplied format names straight to render; validate against supported_formats.
- Load optional serialization gems (msgpack) uniformly across the fleet.
- Test render + convert_from round-trips for each advertised format.
When it happens
Trigger: obj.render(:msgpack) or Puppet::Network::FormatHandler.format(:msgpack).render(obj) where the class lacks to_msgpack — e.g. the msgpack gem not loaded so the model never got msgpack renderers, or a custom class that only defines to_json.
Common situations: Agents or masters requesting msgpack when one side lacks the gem; custom models on FormatSupport without to_data_hash; refactors that dropped a to_* method; formats added by plugins absent on the rendering node.
Related errors
- %{klass} does not respond to %{method}; can not render multi
- #{klass} does not respond to #{intern_multiple_method}; can
- Could not render_multiple to %{format}: %{err}
- Could not render to %{format}: %{err}
- 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/471778c3117994c6.
Report an issue: GitHub.