{"record":{"id":"b6c1495162749da4","repo":"puppetlabs/puppet","slug":"the-code-loaded-from-source-ref-does-not-define-b6c149","errorCode":null,"errorMessage":"The code loaded from %{source_ref} does not define the resource type '%{type_name}' - got '%{got}'.","messagePattern":"The code loaded from %(.+?) does not define the resource type '%(.+?)' - got '%(.+?)'\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb","lineNumber":63,"sourceCode":"        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\n    # the loader is known - hence this mechanism\n    Adapters::LoaderAdapter.adapt(resource_type_impl).loader_name = loader.loader_name\n    resource_type_impl\n  end\nend\nend\nend\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb#L45-L81","documentation":"Raised after the instantiator evaluates the file (with the global scope as closure scope) and the evaluation result is not a Puppet::Pops::Resource::ResourceTypeImpl. The static checks passed, but the single statement evaluated to some other value; the message reports the actual class of the result. Note the code reads `resource_type.class` (the unevaluated model object), so the reported class reflects the parsed expression's class when the result is not the impl.","triggerScenarios":"`parser.evaluate(closure_scope, model)` returns a non-ResourceTypeImpl value while the earlier static shape checks passed -- e.g. the single statement builds the constructor dynamically or the evaluation yields nil/String.","commonSituations":"Edge cases where the parsed shape matched but evaluation diverges; exotic metaprogramming in a Puppet-language type file; Puppet version changes to the Resource API evaluation.","solutions":["Make Resource::ResourceTypeImpl.new(...) a literal, plain call so evaluation returns the impl instance","Inspect the 'got' class in the message to see what evaluation produced and adjust the file","Verify against a known-good resource type file for your Puppet version"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"def resource_type_impl?(obj)\n  obj.is_a?(Puppet::Pops::Resource::ResourceTypeImpl)\nend","tryCatchPattern":"begin\n  impl = loader.load_typed(typed_name)\nrescue ArgumentError => e\n  raise unless e.message.include?(\"does not define the resource type\")\n  warn \"evaluation did not yield a resource type: #{e.message}\"\nend","preventionTips":["Keep the constructor call literal and unconditional","Test resource type files with a compile check after Puppet upgrades","Compare against a known-good type file when this fires"],"tags":["puppet","resource-type","loader","evaluation"],"backgroundTag":"puppet-resource-type-load-validation","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}