{"record":{"id":"22e40dac85609257","repo":"puppetlabs/puppet","slug":"cannot-use-an-unspecific-resource-class-where-a","errorCode":null,"errorMessage":"Cannot use an unspecific Resource['class'] where a Resource['class', name] is expected","messagePattern":"Cannot use an unspecific Resource\\['class'\\] where a Resource\\['class', name\\] is expected","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/parser/scope.rb","lineNumber":1132,"sourceCode":"  # @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":1114,"sourceCodeEnd":1142,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/parser/scope.rb#L1114-L1142","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":"# before\ninclude Class[$role_class]   # $role_class undef -> unspecific Resource['class']\n\n# after\nif $role_class =~ NonEmptyString {\n  include Class[$role_class]\n}","handlingStrategy":"type-guard","validationCode":"include Class[$title] if $title =~ NonEmptyString","typeGuard":"def titled_class?(r)\n  r.is_a?(Puppet::Resource) && r.type =~ /^[Cc]lass$/ && !r.title.nil?\nend","tryCatchPattern":null,"preventionTips":["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."],"tags":["puppet","class-reference","resource","missing-title","include"],"backgroundTag":"invalid-class-reference","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}