{"record":{"id":"5812acd7968f5c98","repo":"puppetlabs/puppet","slug":"serialized-yaml-did-not-contain-a-collection-of-in","errorCode":null,"errorMessage":"Serialized YAML did not contain a collection of instances when calling intern_multiple","messagePattern":"Serialized YAML did not contain a collection of instances when calling intern_multiple","errorType":"exception","errorClass":"Puppet::Network::FormatHandler::FormatError","httpStatus":null,"severity":"error","filePath":"lib/puppet/network/formats.rb","lineNumber":48,"sourceCode":"      Puppet::Node::Facts,\n      Puppet::Node,\n      Puppet::Transaction::Report,\n      Puppet::Resource,\n      Puppet::Resource::Catalog\n    ]\n  end\n\n  def intern(klass, text)\n    data = Puppet::Util::Yaml.safe_load(text, allowed_yaml_classes)\n    data_to_instance(klass, data)\n  rescue Puppet::Util::Yaml::YamlLoadError => e\n    raise Puppet::Network::FormatHandler::FormatError, _(\"Serialized YAML did not contain a valid instance of %{klass}: %{message}\") % { klass: klass, message: e.message }\n  end\n\n  def intern_multiple(klass, text)\n    data = Puppet::Util::Yaml.safe_load(text, allowed_yaml_classes)\n    unless data.respond_to?(:collect)\n      raise Puppet::Network::FormatHandler::FormatError, _(\"Serialized YAML did not contain a collection of instances when calling intern_multiple\")\n    end\n\n    data.collect do |datum|\n      data_to_instance(klass, datum)\n    end\n  rescue Puppet::Util::Yaml::YamlLoadError => e\n    raise Puppet::Network::FormatHandler::FormatError, _(\"Serialized YAML did not contain a valid instance of %{klass}: %{message}\") % { klass: klass, message: e.message }\n  end\n\n  def data_to_instance(klass, data)\n    return data if data.is_a?(klass)\n\n    unless data.is_a? Hash\n      raise Puppet::Network::FormatHandler::FormatError, _(\"Serialized YAML did not contain a valid instance of %{klass}\") % { klass: klass }\n    end\n\n    klass.from_data_hash(data)\n  end","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/network/formats.rb#L30-L66","documentation":"The yaml format's intern_multiple requires the safe_load result to be a collection (respond_to?(:collect)). A syntactically valid YAML document that is a scalar or a single mapping — '--- 42', '--- foo', even a lone instance hash — fails this check and raises FormatError stating a collection is required. The document parsed; its shape is wrong for multi-instance interning.","triggerScenarios":"Klass.convert_from_multiple(:yaml, '--- foo'); a producer calling YAML.dump(single_object) where the consumer expects YAML.dump([obj1, obj2]); sending a one-element mapping document instead of a sequence.","commonSituations":"Batch endpoints receiving single-object documents; fixtures written as single documents; producers whose dump path changed from arrays to single objects.","solutions":["Change the document to a YAML sequence — each item an instance or Hash ('- name: a' entries).","On the producer, dump collections: Puppet::Util::Yaml.dump(items) where items is an Array.","Use intern (convert_from) for genuine single documents.","Add a shape pre-check (respond_to?(:collect)) before calling intern_multiple."],"exampleFix":"# before — widgets.yaml\n# ---\n# id: 1\n# (single mapping → error)\n\n# after\n# ---\n# - id: 1\n# - id: 2\nlist = Widget.convert_from_multiple(:yaml, File.read('widgets.yaml'))","handlingStrategy":"validation","validationCode":"data = Puppet::Util::Yaml.safe_load(text, [])\nraise ArgumentError, 'yaml payload must be a sequence of instances' unless data.respond_to?(:collect)\nitems = Klass.convert_from_multiple(:yaml, text)","typeGuard":null,"tryCatchPattern":"begin\n  items = Klass.convert_from_multiple(:yaml, text)\nrescue Puppet::Network::FormatHandler::FormatError\n  # if the cause is 'not a collection', fall back to single interning\n  items = [Klass.convert_from(:yaml, text)]\nend","preventionTips":["Producers always dump arrays for list endpoints.","Pre-check that loaded YAML responds to collect.","Write fixtures as YAML sequences, never single documents.","Distinguish 'not a collection' from parse errors in error handling."],"tags":["puppet","ruby","yaml","serialization","type-mismatch"],"backgroundTag":"yaml-type-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}