puppetlabs/puppet · error · ArgumentError

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

Error message

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

What it means

Raised by Scope#assert_class_and_title (called from transform_and_assert_classnames for Puppet::Resource and PResourceType arguments) when the resource's type_name is nil or ''. It is the first of three checks: an untyped resource carries no information about what to include, and the include/contain API requires a concrete class reference.

Source

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

  # 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 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. Supply the type: `include Resource['class', 'apache']` — or more idiomatically `include apache`.
  2. In Ruby, validate the object before use: raise a clear error if ref.type.to_s.empty?.
  3. Fix the upstream data so type is always populated when constructing resource references.

Example fix

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

# after
include apache     # or include Resource['class', 'apache']
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, 'resource type missing' if ref.type.nil? || ref.type.to_s.empty?
include ref   # after the check

Type guard

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

Prevention

When it happens

Trigger: `include Resource` (bare Resource type resolves to PResourceType with nil type_name); API users constructing Puppet::Resource.new(nil, 'title') or Puppet::Resource.new('', 'title') and passing it to include/contain/realize; interpolations that were expected to yield Resource['class','name'] but produce an unspecific Resource.

Common situations: Dynamic code that builds resource references from data where the type field is missing; generic orchestration scripts forwarding resource objects to include; refactors dropping the type argument from Resource[...].

Related errors


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