puppetlabs/puppet · error · ArgumentError
Cannot use an unspecific Class[] Type
Error message
Cannot use an unspecific Class[] Type
What it means
Raised by Scope#transform_and_assert_classnames in the PClassType branch when a Class[] type reference carries no class_name. `Class` by itself (a PClassType with class_name == nil) matches any class as a type, but it is not a concrete class that can be included, contained, or realized, so normalization refuses it.
Source
Thrown at lib/puppet/parser/scope.rb:1096
# @return [Array<String>] names after transformation
#
def transform_and_assert_classnames(names)
names.map do |name|
case name
when NilClass
raise ArgumentError, _("Cannot use undef as a class name")
when String
raise ArgumentError, _("Cannot use empty string as a class name") if name.empty?
name.sub(/^([^:]{1,2})/, '::\1')
when Puppet::Resource
assert_class_and_title(name.type, name.title)
name.title.sub(/^([^:]{1,2})/, '::\1')
when Puppet::Pops::Types::PClassType
# TRANSLATORS "Class" and "Type" are Puppet keywords and should not be translated
raise ArgumentError, _("Cannot use an unspecific Class[] Type") unless name.class_name
name.class_name.sub(/^([^:]{1,2})/, '::\1')
when Puppet::Pops::Types::PResourceType
assert_class_and_title(name.type_name, name.title)
name.title.sub(/^([^:]{1,2})/, '::\1')
end.downcase
end
end
# Calls a 3.x or 4.x function by name with arguments given in an array using the 4.x calling convention
# and returns the result.
# Note that it is the caller's responsibility to rescue the given ArgumentError and provide location information
# to aid the user find the problem. The problem is otherwise reported against the source location that
# invoked the function that ultimately called this method.
#
# @return [Object] the result of the called function
# @raise ArgumentError if the function does not existView on GitHub (pinned to e227c27540)
Solutions
- Name the class: `include Class['apache']` or simply `include apache`.
- If the intent was a type check, keep Class on the right side of a match: `assert_type(Class, $ref)` — do not pass it to include.
- In generic Ruby code, verify `klass.class_name` is non-nil before forwarding a PClassType to include/contain.
Example fix
# before include Class # Cannot use an unspecific Class[] Type # after include Class['apache'] # or: include apache
Defensive patterns
Strategy: validation
Validate before calling
# DSL: always include a concrete name include Class['apache'] # Ruby: check specificity before forwarding a type object raise ArgumentError, 'unspecific Class[]' unless pclass_type.class_name
Type guard
p.is_a?(Puppet::Pops::Types::PClassType) && !p.class_name.nil?
Prevention
- Never pass bare Class/Resource metatypes to include/contain.
- In generic code, verify .class_name / .type_name / .title are set before calling include-family APIs.
- Keep Class[...] on the right side of =~ or assert_type for type checks.
When it happens
Trigger: `include Class` (bare, no title), `contain Class`, `Class <| tag == 'x' |>`-adjacent API misuse, or `include Class[$var]` where the interpolation degenerates to an unspecific Class type. Also direct calls like scope.transform_and_assert_classnames([Puppet::Pops::Types::TypeParser.parse('Class')]).
Common situations: Code intended to reference 'the Class metatype' in a type annotation accidentally passed to include; refactoring `Class['name']` references where the ['name'] part was dropped; generic code iterating over type objects and forwarding them to include.
Related errors
- Cannot use undef as a class name
- Cannot use empty string as a class name
- Cannot use an unspecific Resource[] where a Resource['class'
- Cannot use a Resource[%{type_name}] where a Resource['class'
- Cannot use an unspecific Resource['class'] where a Resource[
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/10d4a4ec53b615d2.
Report an issue: GitHub.