puppetlabs/puppet · error · ArgumentError

The code loaded from %{source_ref} does not create the resou

Error message

The code loaded from %{source_ref} does not create the resource type '%{type_name}' - it is empty

What it means

Raised by PuppetResourceTypeImplInstantiator when a Puppet-language resource type definition file contains no statements at all after parsing (Nops are rejected). The instantiator expects code that constructs a resource type via Resource::ResourceTypeImpl.new, so an empty or comments-only file fails with this ArgumentError at load.

Source

Thrown at lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb:35

  # @return [Puppet::Pops::ResourceTypeImpl] - an instantiated ResourceTypeImpl
  #
  def self.create(loader, typed_name, source_ref, pp_code_string)
    parser = Parser::EvaluatingParser.new()

    # parse and validate
    model = parser.parse_string(pp_code_string, source_ref)
    statements = if model.is_a?(Model::Program)
                   if model.body.is_a?(Model::BlockExpression)
                     model.body.statements
                   else
                     [model.body]
                   end
                 else
                   EMPTY_ARRAY
                 end
    statements = statements.reject { |s| s.is_a?(Model::Nop) }
    if statements.empty?
      raise ArgumentError, _("The code loaded from %{source_ref} does not create the resource type '%{type_name}' - it is empty") % { source_ref: source_ref, type_name: typed_name.name }
    end

    rname = Resource::ResourceTypeImpl._pcore_type.name
    unless statements.find do |s|
      if s.is_a?(Model::CallMethodExpression)
        functor_expr = s.functor_expr
        functor_expr.is_a?(Model::NamedAccessExpression) &&
        functor_expr.left_expr.is_a?(Model::QualifiedReference) &&
        functor_expr.left_expr.cased_value == rname &&
        functor_expr.right_expr.is_a?(Model::QualifiedName) &&
        functor_expr.right_expr.value == 'new'
      else
        false
      end
    end
      raise ArgumentError, _("The code loaded from %{source_ref} does not create the resource type '%{type_name}' - no call to %{rname}.new found.") % { source_ref: source_ref, type_name: typed_name.name, rname: rname }
    end

View on GitHub (pinned to e227c27540)

Solutions

  1. Populate the file with a single Resource::ResourceTypeImpl.new(...) call
  2. Delete the file if the resource type is not intended
  3. Confirm via source_ref that the loader is pointed at the intended file

Example fix

# before - modules/mymod/types_greeting/thing.pp (empty file)

# after
Resource::ResourceTypeImpl.new('mymod::thing',
  is_capability: false,
  attributes: {
    message: { type: String, default: 'hello', kind: 'parameter' }
  }
)
Defensive patterns

Strategy: validation

Validate before calling

model = Puppet::Pops::Parser::Parser.new.parse_string(code, source_ref)
stmts = (model.is_a?(Puppet::Pops::Model::Program) ? [model.body].flatten : []).reject { |s| s.is_a?(Puppet::Pops::Model::Nop) }
# approximate: a Program body BlockExpression's statements must be non-empty
raise ArgumentError, "#{source_ref} is empty" if stmts.compact.empty?

Try / catch

begin
  loader.load_typed(typed_name)
rescue ArgumentError => e
  raise unless e.message.include?('it is empty')
  warn "empty resource type file: #{e.message}"
end

Prevention

When it happens

Trigger: Loading a resource type .pp file where `statements` (Program body statements with Model::Nop entries rejected) is empty -- an empty file, whitespace/comments only, or a body that parsed entirely to Nops.

Common situations: Scaffolding tools creating placeholder files; deleting the body but leaving the file; merge conflicts resolved to empty content.

Related errors


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