puppetlabs/puppet · error · ArgumentError

Could not find resource

Error message

Could not find resource '%{target}' for relationship from '%{source}'

What it means

Companion guard to the source check in Relationship#mk_relationship: the target resource of the relationship could not be found in the catalog.

Solutions

  1. Declare the target resource or correct its reference
  2. Avoid relationships to resources in containers that are not evaluated
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/puppet/parser/relationship.rb:48 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/203f311de9b1ca4e. Report an issue: GitHub.

Appendix: source

Thrown at lib/puppet/parser/relationship.rb:48

    @target = target
    @type = type
  end

  def param_name
    PARAM_MAP[type] || raise(ArgumentError, _("Invalid relationship type %{relationship_type}") % { relationship_type: type })
  end

  def mk_relationship(source, target, catalog)
    source_ref = canonical_ref(source)
    target_ref = canonical_ref(target)
    rel_param = param_name

    source_resource = catalog.resource(*source_ref)
    unless source_resource
      raise ArgumentError, _("Could not find resource '%{source}' for relationship on '%{target}'") % { source: source.to_s, target: target.to_s }
    end
    unless catalog.resource(*target_ref)
      raise ArgumentError, _("Could not find resource '%{target}' for relationship from '%{source}'") % { target: target.to_s, source: source.to_s }
    end

    Puppet.debug { "Adding relationship from #{source} to #{target} with '#{param_name}'" }
    if source_resource[rel_param].class != Array
      source_resource[rel_param] = [source_resource[rel_param]].compact
    end
    source_resource[rel_param] << (target_ref[1].nil? ? target_ref[0] : "#{target_ref[0]}[#{target_ref[1]}]")
  end

  private

  # Finds the leftmost alternative for a collector (if it is empty, try its empty alternative recursively until there is
  # either nothing left, or a non empty set is found.
  #
  def leftmost_alternative(x)
    if x.is_a?(Puppet::Pops::Evaluator::Collectors::AbstractCollector)
      collected = x.collected
      return collected.values unless collected.empty?

View on GitHub (pinned to e227c27540)