{"record":{"id":"a9c5df4e51334990","repo":"puppetlabs/puppet","slug":"the-code-loaded-from-source-ref-contains-additi","errorCode":null,"errorMessage":"The code loaded from %{source_ref} contains additional logic - can only contain the type '%{name}'","messagePattern":"The code loaded from %(.+?) contains additional logic - can only contain the type '%(.+?)'","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/loader/type_definition_instantiator.rb","lineNumber":38,"sourceCode":"    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\n    Adapters::LoaderAdapter.adapt(type_definition).loader_name = private_loader.loader_name\n    create_runtime_type(type_definition)\n  end\n\n  def self.create_from_model(type_definition, loader)\n    typed_name = TypedName.new(:type, type_definition.name)\n    type = create_runtime_type(type_definition)\n    loader.set_entry(\n      typed_name,\n      type,\n      type_definition.locator.to_uri(type_definition)","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/loader/type_definition_instantiator.rb#L20-L56","documentation":"After all other checks pass, TypeDefinitionInstantiator.create verifies model.body == type_definition: the type definition must be the entire program body. If the file has extra top-level logic around it — statements, expression, or anything that is not the single definition — this ArgumentError fires. It is the 'your type file contains code besides the type' guard.","triggerScenarios":"types/mytype.pp like `notice('hi')` before/after the alias, a variable assignment `$x = 1` at top level, or an `if` statement wrapping the type definition; the definitions count is 1 so earlier checks pass, but the program body is a Model::Program whose body is not the definition itself.","commonSituations":"Debug statements left in a type file; conditional type definition attempts; people treating types/ files like normal manifests.","solutions":["Strip the file down to the single `type ...` statement; remove notices, assignments, conditionals.","Move any supporting logic into a function or class manifest, not the types/ file.","Note the earlier checks still apply — keep it exactly one definition and nothing else."],"exampleFix":"// before: modules/mymodule/types/mytype.pp\nnotice('loading mytype')\ntype mymodule::mytype = String\n\n// after: modules/mymodule/types/mytype.pp\ntype mymodule::mytype = String","handlingStrategy":"validation","validationCode":"# CI check: types/*.pp program body must be the single definition (no extra logic)\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  abort \"#{f}: contains additional logic beyond the type definition\" unless model.body == model.definitions[0]\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep types/*.pp to a single `type ... =` line (or one object definition block).","Never add notices, assignments, or conditionals to a types/ file; use manifests/ for behavior."],"tags":["puppet","type-alias","types-directory","extra-logic","argumenterror"],"backgroundTag":"puppet-type-file-extra-content","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}