{"record":{"id":"2cf90506081508a0","repo":"puppetlabs/puppet","slug":"the-code-loaded-from-source-ref-does-not-define-2cf905","errorCode":null,"errorMessage":"The code loaded from %{source_ref} does not define the type '%{name}' - it is empty.","messagePattern":"The code loaded from %(.+?) does not define the type '%(.+?)' - it is empty\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/loader/type_definition_instantiator.rb","lineNumber":17,"sourceCode":"# frozen_string_literal: true\n\n# The TypeDefinitionInstantiator instantiates a type alias or a type definition\n#\nmodule Puppet::Pops\nmodule Loader\nclass TypeDefinitionInstantiator\n  def self.create(loader, typed_name, source_ref, pp_code_string)\n    # parse and validate\n    parser = Parser::EvaluatingParser.new()\n    model = parser.parse_string(pp_code_string, source_ref)\n    # Only one type is allowed (and no other definitions)\n\n    name = typed_name.name\n    case model.definitions.size\n    when 0\n      raise ArgumentError, _(\"The code loaded from %{source_ref} does not define the type '%{name}' - it is empty.\") % { source_ref: source_ref, name: name }\n    when 1\n      # ok\n    else\n      raise ArgumentError,\n            _(\"The code loaded from %{source_ref} must contain only the type '%{name}' - it has additional definitions.\") % { source_ref: source_ref, name: name }\n    end\n    type_definition = model.definitions[0]\n\n    unless type_definition.is_a?(Model::TypeAlias) || type_definition.is_a?(Model::TypeDefinition)\n      raise ArgumentError,\n            _(\"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 }\n    end\n\n    actual_name = type_definition.name\n    unless name == actual_name.downcase\n      raise ArgumentError,\n            _(\"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 }\n    end","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/loader/type_definition_instantiator.rb#L1-L35","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","If the file is a stray leftover, delete it so the loader does not pick it up for that type name.","Verify the file the loader actually resolved (path is in source_ref) — the fix must go in that exact file."],"exampleFix":"// before: modules/mymodule/types/mytype.pp is empty\n\n// after\n type mymodule::mytype = String[1, 50]","handlingStrategy":"validation","validationCode":"# Fail fast in CI: every types/*.pp must contain exactly one type definition\nrequire 'puppet'\nrequire 'puppet/pops'\n\nDir['modules/*/types/**/*.pp'].each do |f|\n  model = Puppet::Pops::Parser::EvaluatingParser.new.parse_string(File.read(f), f)\n  defs = model.definitions\n  next if defs.size == 1 && defs[0].is_a?(Puppet::Pops::Model::TypeAlias | Puppet::Pops::Model::TypeDefinition rescue false)\n  abort \"#{f}: must define exactly one type alias or type definition (found #{defs.size})\"\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One type per file, file name matching the type's last name segment.","Lint types/ files in CI (empty-file and definition-count checks are cheap).","Never let generated placeholder files into types/; review rsync/deploy diffs for zero-byte .pp files."],"tags":["puppet","type-alias","types-directory","autoload","argumenterror"],"backgroundTag":"puppet-type-definition-empty-file","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}