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
- Provide the title: `include Class['apache']` or `include apache`.
- Guard dynamic titles: `if $title_var { include Class[$title_var] }`.
- 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
- Ensure variables used as Class[...] titles are NonEmptyString before interpolation.
- When building class resources in Ruby, always pass a non-nil title.
- Validate rows of data-driven include tables (class column non-empty) at load time.
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
- Cannot use an unspecific Resource[] where a Resource['class'
- Cannot use a Resource[%{type_name}] where a Resource['class'
- Cannot use undef as a class name
- Cannot use empty string as a class name
- Cannot use an unspecific Class[] Type
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/22e40dac85609257.
Report an issue: GitHub.