puppetlabs/puppet · error · ArgumentError

Cannot use an unspecific Resource['class'] where a Resource[

Error message

Cannot use an unspecific Resource['class'] where a Resource['class', name] is expected

What it means

Raised by Scope#assert_class_and_title in the third branch: the resource type IS 'Class' but the title is nil. A Resource['class'] without a name does not identify any includeable class, so class-name normalization refuses it. This is the 'typed but untitled' sibling of the unspecific-Class[] error.

Source

Thrown at lib/puppet/parser/scope.rb:1132

  # @raise ArgumentError if the function does not exist
  def call_function(func_name, args, &block)
    Puppet::Pops::Parser::EvaluatingParser.new.evaluator.external_call_function(func_name, args, self, &block)
  end

  private

  def assert_class_and_title(type_name, title)
    if type_name.nil? || type_name == ''
      # TRANSLATORS "Resource" is a class name and should not be translated
      raise ArgumentError, _("Cannot use an unspecific Resource[] where a Resource['class', name] is expected")
    end
    unless type_name =~ /^[Cc]lass$/
      # TRANSLATORS "Resource" is a class name and should not be translated
      raise ArgumentError, _("Cannot use a Resource[%{type_name}] where a Resource['class', name] is expected") % { type_name: type_name }
    end
    if title.nil?
      # TRANSLATORS "Resource" is a class name and should not be translated
      raise ArgumentError, _("Cannot use an unspecific Resource['class'] where a Resource['class', name] is expected")
    end
  end

  def extend_with_functions_module
    root = Puppet.lookup(:root_environment)
    extend Puppet::Parser::Functions.environment_module(root)
    extend Puppet::Parser::Functions.environment_module(environment) if environment != root
  end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Provide the title: `include Class['apache']` or `include apache`.
  2. Guard dynamic titles: `if $title_var { include Class[$title_var] }`.
  3. When constructing Puppet::Resource in Ruby, validate `ref.title` is non-nil before passing it on.

Example fix

# before
include Class[$role_class]   # $role_class undef -> unspecific Resource['class']

# after
if $role_class =~ NonEmptyString {
  include Class[$role_class]
}
Defensive patterns

Strategy: type-guard

Validate before calling

include Class[$title] if $title =~ NonEmptyString

Type guard

def titled_class?(r)
  r.is_a?(Puppet::Resource) && r.type =~ /^[Cc]lass$/ && !r.title.nil?
end

Prevention

When it happens

Trigger: `include Class[$missing]` where $missing is undef produces a class-typed reference with nil title in some evaluation paths; direct API use `Puppet::Resource.new('class', nil)` or Resource['class'] with no title passed to include/contain; realize() over resource lists containing an untitled class reference.

Common situations: Interpolating a title from a variable that is undefined; data-driven include lists where the title column is empty; test fixtures constructing class resources without titles.

Related errors


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