{"record":{"id":"583aa78b705236dc","repo":"puppetlabs/puppet","slug":"cannot-use-an-unspecific-resource-where-a-resour","errorCode":null,"errorMessage":"Cannot use an unspecific Resource[] where a Resource['class', name] is expected","messagePattern":"Cannot use an unspecific Resource\\[\\] where a Resource\\['class', name\\] is expected","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/parser/scope.rb","lineNumber":1124,"sourceCode":"\n  # Calls a 3.x or 4.x function by name with arguments given in an array using the 4.x calling convention\n  # and returns the result.\n  # Note that it is the caller's responsibility to rescue the given ArgumentError and provide location information\n  # 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":1106,"sourceCodeEnd":1142,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/parser/scope.rb#L1106-L1142","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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[...].","solutions":["Supply the type: `include Resource['class', 'apache']` — or more idiomatically `include apache`.","In Ruby, validate the object before use: raise a clear error if ref.type.to_s.empty?.","Fix the upstream data so type is always populated when constructing resource references."],"exampleFix":"# before\ninclude Resource   # Cannot use an unspecific Resource[] where a Resource['class', name] is expected\n\n# after\ninclude apache     # or include Resource['class', 'apache']","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'resource type missing' if ref.type.nil? || ref.type.to_s.empty?\ninclude ref   # after the check","typeGuard":"def class_resource?(r)\n  r.is_a?(Puppet::Resource) && !r.type.to_s.empty? && r.type =~ /^[Cc]lass$/ && !r.title.nil?\nend","tryCatchPattern":null,"preventionTips":["Always construct resource references with both type and title: Resource['class', 'name'].","Validate data-driven type fields before building Puppet::Resource objects.","Prefer plain class-name strings over synthesized resource objects when calling include."],"tags":["puppet","class-reference","resource","include","unspecific"],"backgroundTag":"invalid-class-reference","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}