puppetlabs/puppet · error · Puppet::Parser::Compiler::CatalogValidationError

Could not find resource '%{res}' in parameter '%{param}'

Error message

Could not find resource '%{res}' in parameter '%{param}'

What it means

After parsing a relationship parameter succeeds, the validator checks the referenced resource actually exists in the compiled catalog (relationship_validator.rb:33-38). `catalog.resource('Type[Title]')` returns nil when no resource with that type and title was declared, collected, or realized, so the catalog cannot contain the dependency edge and validation aborts with CatalogValidationError. It means the reference is well-formed but points at a resource that never made it into the catalog.

Source

Thrown at lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb:36

    private

    def validate_relationship(param)
      # the referenced resource must exist
      refs = param.value.is_a?(Array) ? param.value.flatten : [param.value]
      refs.each do |r|
        next if r.nil? || r == :undef

        res = r.to_s
        begin
          found = catalog.resource(res)
        rescue ArgumentError => e
          # Raise again but with file and line information
          raise CatalogValidationError.new(e.message, param.file, param.line)
        end
        unless found
          msg = _("Could not find resource '%{res}' in parameter '%{param}'") % { res: res, param: param.name.to_s }
          raise CatalogValidationError.new(msg, param.file, param.line)
        end
      end
    end
  end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Declare the missing resource in the same or an included class: add `file { '/etc/app.conf': ensure => file }`
  2. For class references, make sure the class is declared: `include profile::web` on this node before something requires Class['profile::web']
  3. Realize virtual resources (`realize(File['/etc/app.conf'])`) or make sure the collector filter matches
  4. Check exact title equality (path case, trailing slashes) against the declaration

Example fix

# before
service { 'app':
  ensure  => running,
  require => File['/etc/app.conf'],  # never declared -> validation error
}
# after
file { '/etc/app.conf':
  ensure => file,
}
service { 'app':
  ensure  => running,
  require => File['/etc/app.conf'],
}
Defensive patterns

Strategy: validation

Validate before calling

# Ruby: verify a reference resolves before compiling
cat = compiler.compile rescue nil
# or proactively on an existing catalog:
raise ArgumentError, 'File[/etc/app.conf] not in catalog' unless catalog.resource('File[/etc/app.conf]')

Try / catch

begin
  compiler.compile
rescue Puppet::Parser::Compiler::CatalogValidationError => e
  # message names the exact missing reference and the parameter that cited it
  raise unless e.message.include?("Could not find resource")
end

Prevention

When it happens

Trigger: `require => File['/etc/app.conf']` where that file resource is never declared; `require => Class['profile::web']` when that class is not declared anywhere (include/contain/class {'...'}); referencing a resource declared inside a class that is not included on this node; relying on a resource realized by a collector with a filter that matches nothing (<<| |>> with no matches); title case mismatch such as File['/ETC/app'] vs declared File['/etc/app'] for types with case-insensitive titles.

Common situations: Refactoring splits a class and the require target moves to a profile that is no longer included; node classification (ENC/Hiera) stops declaring a class but another class still requires it; exported resources not yet collected on first run of a fresh node; typos in long file paths inside require brackets; relying on resource defaults or virtual resources (@file) without realizing them.

Related errors


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