{"record":{"id":"5847ed86ea4a7f7e","repo":"puppetlabs/puppet","slug":"cannot-add-resource-resource-1-before-resourc","errorCode":null,"errorMessage":"Cannot add resource %{resource_1} before %{resource_2} because %{resource_2} is not yet in the catalog","messagePattern":"Cannot add resource %(.+?) before %(.+?) because %(.+?) is not yet in the catalog","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/resource/catalog.rb","lineNumber":104,"sourceCode":"  # Returns [nil, nil] if '[' ']' not detected.\n  #\n  def title_key_for_ref(ref)\n    s = ref.index('[')\n    e = ref.rindex(']')\n    if s && e && e > s\n      a = [ref[0, s], ref[s + 1, e - s - 1]]\n    else\n      a = [nil, nil]\n    end\n    a\n  end\n\n  def add_resource_before(other, *resources)\n    resources.each do |resource|\n      other_title_key = title_key_for_ref(other.ref)\n      idx = @resources.index(other_title_key)\n      if idx.nil?\n        raise ArgumentError, _(\"Cannot add resource %{resource_1} before %{resource_2} because %{resource_2} is not yet in the catalog\") %\n                             { resource_1: resource.ref, resource_2: other.ref }\n      end\n      add_one_resource(resource, idx)\n    end\n  end\n\n  # Add `resources` to the catalog after `other`. WARNING: adding\n  # multiple resources will produce the reverse ordering, e.g. calling\n  # `add_resource_after(A, [B,C])` will result in `[A,C,B]`.\n  def add_resource_after(other, *resources)\n    resources.each do |resource|\n      other_title_key = title_key_for_ref(other.ref)\n      idx = @resources.index(other_title_key)\n      if idx.nil?\n        raise ArgumentError, _(\"Cannot add resource %{resource_1} after %{resource_2} because %{resource_2} is not yet in the catalog\") %\n                             { resource_1: resource.ref, resource_2: other.ref }\n      end\n      add_one_resource(resource, idx + 1)","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/resource/catalog.rb#L86-L122","documentation":"Error \"Cannot add resource %{resource_1} before %{resource_2} because %{resource_2} is not yet in the catalog\" thrown in puppetlabs/puppet.","triggerScenarios":"Thrown at lib/puppet/resource/catalog.rb:104 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}