{"record":{"id":"03f43d949ec27f42","repo":"puppetlabs/puppet","slug":"klass-does-not-respond-to-method-can-not-re","errorCode":null,"errorMessage":"%{klass} does not respond to %{method}; can not render multiple instances to %{mime}","messagePattern":"%(.+?) does not respond to %(.+?); can not render multiple instances to %(.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"lib/puppet/network/format.rb","lineNumber":78,"sourceCode":"\n    raise NotImplementedError, \"#{klass} does not respond to #{intern_multiple_method}; can not intern multiple instances from #{mime}\"\n  end\n\n  def mime=(mime)\n    @mime = mime.to_s.downcase\n  end\n\n  def render(instance)\n    return instance.send(render_method) if instance.respond_to?(render_method)\n\n    raise NotImplementedError, \"#{instance.class} does not respond to #{render_method}; can not render instances to #{mime}\"\n  end\n\n  def render_multiple(instances)\n    # This method implicitly assumes that all instances are of the same type.\n    return instances[0].class.send(render_multiple_method, instances) if instances[0].class.respond_to?(render_multiple_method)\n\n    raise NotImplementedError, _(\"%{klass} does not respond to %{method}; can not render multiple instances to %{mime}\") %\n                               { klass: instances[0].class, method: render_multiple_method, mime: mime }\n  end\n\n  def required_methods_present?(klass)\n    [:intern_method, :intern_multiple_method, :render_multiple_method].each do |name|\n      return false unless required_method_present?(name, klass, :class)\n    end\n\n    return false unless required_method_present?(:render_method, klass, :instance)\n\n    true\n  end\n\n  def supported?(klass)\n    suitable? and required_methods_present?(klass)\n  end\n\n  def to_s","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/network/format.rb#L60-L96","documentation":"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 ...'.","triggerScenarios":"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.","commonSituations":"Search/list REST handlers serializing arrays of indirected models; custom faces returning arrays; formats registered with only a single render method.","solutions":["Define the class-level multiple renderer, e.g. def self.to_json_multiple(list) = Puppet::Util::Json.dump(list.map(&:to_data_hash)) end.","Guard empty lists before calling render_multiple (dispatch reads instances[0]).","Pick the format from supported_formats so the full method set exists.","For custom formats, provide a render_multiple proc in Puppet::Network::FormatHandler.create."],"exampleFix":"# before\nclass Widget\n  include Puppet::Network::FormatSupport\n  def to_data_hash = { 'id' => @id }\nend\nWidget.render_multiple(:json, widgets) # Widget has no to_json_multiple\n\n# after\nclass Widget\n  def self.to_json_multiple(list) = Puppet::Util::Json.dump(list.map(&:to_data_hash))\nend","handlingStrategy":"fallback","validationCode":"return '[]' if instances.empty?\nraise ArgumentError, 'mixed classes in list' unless instances.map(&:class).uniq.size == 1\nfmt_name = Widget.supported_formats.include?(:json) ? :json : Widget.default_format\nWidget.render_multiple(fmt_name, instances)","typeGuard":"def renders_multiple?(klass, format_name)\n  fmt = Puppet::Network::FormatHandler.format(format_name)\n  !fmt.nil? && klass.respond_to?(fmt.render_multiple_method)\nend","tryCatchPattern":"begin\n  Widget.render_multiple(:json, instances)\nrescue Puppet::Network::FormatHandler::FormatError, NotImplementedError\n  # degrade to per-instance rendering when the multiple renderer is missing\n  '[' + instances.map { |i| i.render(:json) }.join(',') + ']'\nend","preventionTips":["Implement single and multiple serializers together; they drift silently otherwise.","Short-circuit empty arrays before render_multiple — dispatch reads instances[0].","Ensure lists are homogeneous; dispatch keys off instances[0].class.","Round-trip test arrays (empty, single, many) in CI."],"tags":["puppet","ruby","serialization","formats","rendering","interface"],"backgroundTag":"missing-interface-method","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}