{"record":{"id":"2bf3add00e8bab68","repo":"puppetlabs/puppet","slug":"the-code-loaded-from-source-ref-must-contain-on-2bf3ad","errorCode":null,"errorMessage":"The code loaded from %{source_ref} must contain only the creation of resource type '%{type_name}' - it has additional logic.","messagePattern":"The code loaded from %(.+?) must contain only the creation of resource type '%(.+?)' - it has additional logic\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb","lineNumber":55,"sourceCode":"\n    rname = Resource::ResourceTypeImpl._pcore_type.name\n    unless statements.find do |s|\n      if s.is_a?(Model::CallMethodExpression)\n        functor_expr = s.functor_expr\n        functor_expr.is_a?(Model::NamedAccessExpression) &&\n        functor_expr.left_expr.is_a?(Model::QualifiedReference) &&\n        functor_expr.left_expr.cased_value == rname &&\n        functor_expr.right_expr.is_a?(Model::QualifiedName) &&\n        functor_expr.right_expr.value == 'new'\n      else\n        false\n      end\n    end\n      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 }\n    end\n\n    unless statements.size == 1\n      raise ArgumentError, _(\"The code loaded from %{source_ref} must contain only the creation of resource type '%{type_name}' - it has additional logic.\") % { source_ref: source_ref, type_name: typed_name.name }\n    end\n\n    closure_scope = Puppet.lookup(:global_scope) { {} }\n    resource_type_impl = parser.evaluate(closure_scope, model)\n\n    unless resource_type_impl.is_a?(Puppet::Pops::Resource::ResourceTypeImpl)\n      got = resource_type.class\n      raise ArgumentError, _(\"The code loaded from %{source_ref} does not define the resource type '%{type_name}' - got '%{got}'.\") % { source_ref: source_ref, type_name: typed_name.name, got: got }\n    end\n\n    unless resource_type_impl.name == typed_name.name\n      expected = typed_name.name\n      actual = resource_type_impl.name\n      raise ArgumentError, _(\"The code loaded from %{source_ref} produced resource type with the wrong name, expected '%{expected}', actual '%{actual}'\") % { source_ref: source_ref, expected: expected, actual: actual }\n    end\n\n    # Adapt the resource type definition with loader - this is used from logic contained in it body to find the\n    # loader to use when making calls to the new function API. Such logic have a hard time finding the closure (where","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb#L37-L73","documentation":"Raised by PuppetResourceTypeImplInstantiator when the file contains the Resource::ResourceTypeImpl.new call plus anything else. The instantiator requires statements.size == 1 -- the file must be only the creation call, with no additional expressions or definitions.","triggerScenarios":"`statements.size != 1` after the constructor-call check passed: e.g. the creation call plus a notice() call, an assignment, or a second creation call in the same file.","commonSituations":"Adding debug statements or comments-as-code near the call; defining two resource types in one file; leftover scaffolding expressions.","solutions":["Reduce the file to exactly one statement: the Resource::ResourceTypeImpl.new(...) call","Move each additional resource type to its own file","Move helper logic into functions or plan code, not the type file"],"exampleFix":"# before\nnotice('defining thing')\nResource::ResourceTypeImpl.new('mymod::thing', attributes: { ... })\n\n# after\nResource::ResourceTypeImpl.new('mymod::thing', attributes: { ... })","handlingStrategy":"validation","validationCode":"raise ArgumentError, \"expected exactly 1 statement, got #{statements.size}\" unless statements.size == 1","typeGuard":null,"tryCatchPattern":"begin\n  loader.load_typed(typed_name)\nrescue ArgumentError => e\n  raise unless e.message.include?('additional logic')\n  warn \"trim resource type file to one statement: #{e.message}\"\nend","preventionTips":["Keep resource type files to exactly the one constructor call","One resource type per file","Put comments above the call, never expressions beside it"],"tags":["puppet","resource-type","loader","puppet-language"],"backgroundTag":"puppet-resource-type-load-validation","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}