{"record":{"id":"9b69de4d64a1fad8","repo":"puppetlabs/puppet","slug":"could-not-render-multiple-to-format-err","errorCode":null,"errorMessage":"Could not render_multiple to %{format}: %{err}","messagePattern":"Could not render_multiple to %(.+?): %(.+?)","errorType":"exception","errorClass":"Puppet::Network::FormatHandler::FormatError","httpStatus":null,"severity":"error","filePath":"lib/puppet/network/format_support.rb","lineNumber":31,"sourceCode":"    def convert_from(format, data)\n      get_format(format).intern(self, data)\n    rescue => err\n      # TRANSLATORS \"intern\" is a function name and should not be translated\n      raise Puppet::Network::FormatHandler::FormatError, _(\"Could not intern from %{format}: %{err}\") % { format: format, err: err }, err.backtrace\n    end\n\n    def convert_from_multiple(format, data)\n      get_format(format).intern_multiple(self, data)\n    rescue => err\n      # TRANSLATORS \"intern_multiple\" is a function name and should not be translated\n      raise Puppet::Network::FormatHandler::FormatError, _(\"Could not intern_multiple from %{format}: %{err}\") % { format: format, err: err }, err.backtrace\n    end\n\n    def render_multiple(format, instances)\n      get_format(format).render_multiple(instances)\n    rescue => err\n      # TRANSLATORS \"render_multiple\" is a function name and should not be translated\n      raise Puppet::Network::FormatHandler::FormatError, _(\"Could not render_multiple to %{format}: %{err}\") % { format: format, err: err }, err.backtrace\n    end\n\n    def default_format\n      supported_formats[0]\n    end\n\n    def support_format?(name)\n      Puppet::Network::FormatHandler.format(name).supported?(self)\n    end\n\n    def supported_formats\n      result = format_handler.formats.collect do |f|\n        format_handler.format(f)\n      end.find_all do |f|\n        f.supported?(self)\n      end.sort do |a, b|\n        # It's an inverse sort -- higher weight formats go first.\n        b.weight <=> a.weight","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/network/format_support.rb#L13-L49","documentation":"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).","triggerScenarios":"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].","commonSituations":"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.","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."],"exampleFix":"# before\nWidget.render_multiple(:json, widgets) # FormatError wrapping NotImplementedError/NoMethodError\n\n# after\nreturn '[]' if widgets.empty?\npayload = widgets.map { |w| w.render(:json) }.join(',')\n\"[#{payload}]\"","handlingStrategy":"fallback","validationCode":"return '[]' if instances.empty?\nraise ArgumentError, 'mixed classes in list' unless instances.map(&:class).uniq.size == 1","typeGuard":null,"tryCatchPattern":"begin\n  Widget.render_multiple(:json, instances)\nrescue Puppet::Network::FormatHandler::FormatError\n  # degrade to per-instance rendering\n  '[' + instances.map { |i| i.render(:json) }.join(',') + ']'\nend","preventionTips":["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."],"tags":["puppet","ruby","serialization","rendering","formats"],"backgroundTag":"serialization-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}