puppetlabs/puppet · error · ArgumentError

The code loaded from %{source_ref} does not define the type

Error message

The code loaded from %{source_ref} does not define the type '%{name}' - it is empty.

What it means

TypeDefinitionInstantiator.create is called when a Puppet type alias/definition (e.g. Mod::Mytype) is autoloaded from a module's types/ directory. It parses the .pp source and requires the file to define exactly one type. This ArgumentError fires when model.definitions.size == 0: the file parsed successfully but contains no definitions at all — an empty (or comments/whitespace-only) .pp file was found where the type was expected.

Source

Thrown at lib/puppet/pops/loader/type_definition_instantiator.rb:17

# frozen_string_literal: true

# The TypeDefinitionInstantiator instantiates a type alias or a type definition
#
module Puppet::Pops
module Loader
class TypeDefinitionInstantiator
  def self.create(loader, typed_name, source_ref, pp_code_string)
    # parse and validate
    parser = Parser::EvaluatingParser.new()
    model = parser.parse_string(pp_code_string, source_ref)
    # Only one type is allowed (and no other definitions)

    name = typed_name.name
    case model.definitions.size
    when 0
      raise ArgumentError, _("The code loaded from %{source_ref} does not define the type '%{name}' - it is empty.") % { source_ref: source_ref, name: name }
    when 1
      # ok
    else
      raise ArgumentError,
            _("The code loaded from %{source_ref} must contain only the type '%{name}' - it has additional definitions.") % { source_ref: source_ref, name: name }
    end
    type_definition = model.definitions[0]

    unless type_definition.is_a?(Model::TypeAlias) || type_definition.is_a?(Model::TypeDefinition)
      raise ArgumentError,
            _("The code loaded from %{source_ref} does not define the type '%{name}' - no type alias or type definition found.") % { source_ref: source_ref, name: name }
    end

    actual_name = type_definition.name
    unless name == actual_name.downcase
      raise ArgumentError,
            _("The code loaded from %{source_ref} produced type with the wrong name, expected '%{name}', actual '%{actual_name}'") % { source_ref: source_ref, name: name, actual_name: actual_name }
    end

View on GitHub (pinned to e227c27540)

Solutions

  1. Open the file named in source_ref and add the type definition: `type mod::mytype = String[1,50]` (alias) or a full `type Mod::Mytype << ... >>` object definition.
  2. If the file is a stray leftover, delete it so the loader does not pick it up for that type name.
  3. Verify the file the loader actually resolved (path is in source_ref) — the fix must go in that exact file.

Example fix

// before: modules/mymodule/types/mytype.pp is empty

// after
 type mymodule::mytype = String[1, 50]
Defensive patterns

Strategy: validation

Validate before calling

# Fail fast in CI: every types/*.pp must contain exactly one type definition
require 'puppet'
require 'puppet/pops'

Dir['modules/*/types/**/*.pp'].each do |f|
  model = Puppet::Pops::Parser::EvaluatingParser.new.parse_string(File.read(f), f)
  defs = model.definitions
  next if defs.size == 1 && defs[0].is_a?(Puppet::Pops::Model::TypeAlias | Puppet::Pops::Model::TypeDefinition rescue false)
  abort "#{f}: must define exactly one type alias or type definition (found #{defs.size})"
end

Prevention

When it happens

Trigger: Module has types/mytype.pp that is empty or contains only comments/no leading-space tabs? Puppet code references Mod::Mytype, the loader resolves it to <module>/types/mytype.pp, parsing yields zero definitions, and create() raises with the source_ref of the empty file.

Common situations: A placeholder file committed empty by mistake; a deploy/rsync that truncated the file; a rename that left a stray empty file; Windows BOM/encoding making content invisible to the parser is unlikely but zero-byte files from git merge conflicts are common.

Related errors


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