{"record":{"id":"ae980d17dd828e5e","repo":"puppetlabs/puppet","slug":"cannot-use-a-resource-type-name-where-a-resour","errorCode":null,"errorMessage":"Cannot use a Resource[%{type_name}] where a Resource['class', name] is expected","messagePattern":"Cannot use a Resource\\[%(.+?)\\] where a Resource\\['class', name\\] is expected","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/parser/scope.rb","lineNumber":1128,"sourceCode":"  # to aid the user find the problem. The problem is otherwise reported against the source location that\n  # invoked the function that ultimately called this method.\n  #\n  # @return [Object] the result of the called function\n  # @raise ArgumentError if the function does not exist\n  def call_function(func_name, args, &block)\n    Puppet::Pops::Parser::EvaluatingParser.new.evaluator.external_call_function(func_name, args, self, &block)\n  end\n\n  private\n\n  def assert_class_and_title(type_name, title)\n    if type_name.nil? || type_name == ''\n      # TRANSLATORS \"Resource\" is a class name and should not be translated\n      raise ArgumentError, _(\"Cannot use an unspecific Resource[] where a Resource['class', name] is expected\")\n    end\n    unless type_name =~ /^[Cc]lass$/\n      # TRANSLATORS \"Resource\" is a class name and should not be translated\n      raise ArgumentError, _(\"Cannot use a Resource[%{type_name}] where a Resource['class', name] is expected\") % { type_name: type_name }\n    end\n    if title.nil?\n      # TRANSLATORS \"Resource\" is a class name and should not be translated\n      raise ArgumentError, _(\"Cannot use an unspecific Resource['class'] where a Resource['class', name] is expected\")\n    end\n  end\n\n  def extend_with_functions_module\n    root = Puppet.lookup(:root_environment)\n    extend Puppet::Parser::Functions.environment_module(root)\n    extend Puppet::Parser::Functions.environment_module(environment) if environment != root\n  end\nend\n","sourceCodeStart":1110,"sourceCodeEnd":1142,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/parser/scope.rb#L1110-L1142","documentation":"Raised by Scope#assert_class_and_title when a resource reference IS typed but its type is not 'Class' (case-insensitive /^[Cc]lass$/). include/contain operate on classes only; passing e.g. File['/tmp/x'] means the caller asked to include a non-class resource, which the class-name normalization API rejects with the offending type name in the message.","triggerScenarios":"`include File['/tmp/config']`, `contain Service['httpd']`, or `include Resource['file', '/tmp/x']` — any concrete non-class resource reference forwarded to include/contain/realize's class path. Also Ruby: scope.transform_and_assert_classnames([Puppet::Resource.new('file', '/tmp/x')]).","commonSituations":"Confusing `include` (classes) with resource declaration; code intended to express a dependency (`Class['x'] -> File['/y']`) accidentally used as an include argument; generic loops over mixed resource/class references.","solutions":["Declare the resource instead of including it: `file { '/tmp/config': ensure => present }`.","If you meant a relationship, use the chaining/require syntax: `Class['apache'] -> File['/tmp/x']` or `require => Class['apache']`.","For classes, reference them as Class['name'] or a bare name: `include Class['apache']`."],"exampleFix":"# before\ninclude File['/etc/app.conf']   # Cannot use a Resource[file] where a Resource['class', name] is expected\n\n# after\nfile { '/etc/app/conf.ini': ensure => file }\n# or, if a dependency was intended:\ninclude app\nclass { 'app': require => File['/etc/app/conf.ini'] }","handlingStrategy":"validation","validationCode":"# DSL: include only classes; declare resources directly\ninclude apache          # class\nfile { '/tmp/x': ensure => present }   # resource declaration\n# Ruby:\nraise ArgumentError, 'not a class' unless type_name =~ /^[Cc]lass$/","typeGuard":"def class_ref?(r)\n  r.is_a?(Puppet::Resource) && r.type.to_s =~ /^[Cc]lass$/\nend","tryCatchPattern":null,"preventionTips":["Use include/contain exclusively for classes; use resource declarations for resources.","Express dependencies with chaining arrows or require/before, not include arguments.","Lint for include followed by a bracketed non-Class resource reference."],"tags":["puppet","class-reference","resource","include","wrong-type"],"backgroundTag":"invalid-class-reference","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}