{"record":{"id":"4afae565cfa4e16d","repo":"puppetlabs/puppet","slug":"the-code-loaded-from-source-ref-does-not-define-4afae5","errorCode":null,"errorMessage":"The code loaded from %{source_ref} does not define the type '%{name}' - no type alias or type definition found.","messagePattern":"The code loaded from %(.+?) does not define the type '%(.+?)' - no type alias or type definition found\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/loader/type_definition_instantiator.rb","lineNumber":27,"sourceCode":"    # 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\n\n    unless model.body == type_definition\n      raise ArgumentError,\n            _(\"The code loaded from %{source_ref} contains additional logic - can only contain the type '%{name}'\") % { source_ref: source_ref, name: name }\n    end\n\n    # Adapt the type definition with loader - this is used from logic contained in its body to find the\n    # loader to use when resolving contained aliases API. Such logic have a hard time finding the closure (where\n    # the loader is known - hence this mechanism\n    private_loader = loader.private_loader","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/loader/type_definition_instantiator.rb#L9-L45","documentation":"Raised by TypeDefinitionInstantiator.create when the file has exactly one definition, but that definition is neither a Model::TypeAlias nor a Model::TypeDefinition. The types/ directory may only contain type aliases (`type X = ...`) or object type definitions (`type X << ... >>`); a lone class, define, function, or site statement in that slot fails this check.","triggerScenarios":"types/mytype.pp whose only content is `class mymodule::mytype { ... }` or `define mymodule::mytype (...) { ... }`, then any Puppet code or resource declaration that causes the loader to autoload Mod::Mytype as a type.","commonSituations":"Misreading the types/ directory purpose and putting a class manifest there; converting a class to a type and leaving the class in place; file committed into the wrong directory.","solutions":["Move class/define manifests out of types/ into manifests/.","Replace the content with a real type alias or type definition matching the file name.","If the type is not needed, delete the file so lookups of that name fail cleanly instead of loading junk."],"exampleFix":"// before: modules/mymodule/types/mytype.pp\nclass mymodule::mytype ($x) { notify { $x: } }\n\n// after: modules/mymodule/types/mytype.pp\ntype mymodule::mytype = String[1, 50]","handlingStrategy":"validation","validationCode":"# CI check: the single definition in types/*.pp must be a type alias or 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  d = model.definitions[0]\n  next if d && (d.is_a?(Puppet::Pops::Model::TypeAlias) || d.is_a?(Puppet::Pops::Model::TypeDefinition))\n  abort \"#{f}: contains a #{d.class} — types/ only allows type aliases / type definitions\"\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep classes and defined types in manifests/ only; types/ is exclusively for type aliases and object type definitions.","Code-review anything landing in types/ for the `type` keyword as the first token."],"tags":["puppet","type-alias","types-directory","wrong-definition-kind","argumenterror"],"backgroundTag":"puppet-type-definition-wrong-kind","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}